> For the complete documentation index, see [llms.txt](https://manual.dxable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.dxable.com/1password/kubernetes-injector.md).

# Kubernetes Injector

[1Password Kubernetes Secrets Injector は、サービス アカウント](https://developer.1password.com/docs/service-accounts/)または[Connect サーバーを](https://developer.1password.com/docs/connect/)環境変数として使用して 1Password シークレットを Kubernetes ポッドまたはデプロイメントに挿入できるようにする変更 Webhook を実装します。

1Password [Kubernetes Operator](https://developer.1password.com/docs/k8s/k8s-operator/)とは異なり、Secrets Injector はリソースにシークレットを割り当てるときに Kubernetes Secret をCreateしません。Kubernetes Operator と Kubernetes Injector を比較するには、[Kubernetes 統合を参照してください。](https://developer.1password.com/docs/k8s/k8s-integrations/)

ヒント

1Password サービス アカウントで Kubernetes Secrets Injector を使う方法を紹介します。

<https://youtu.be/WS1CAooBqog>

### **Requirements** <a href="#pmgxhcqci51j" id="pmgxhcqci51j"></a>

Kubernetes Injector を使う前に、次の点を確認してください。

* 1Passwordに[サインアップします](https://start.1password.com/sign-up/plan)。
* Kubernetesのデプロイメントを用意します。minikube[を使うこともできます](https://minikube.sigs.k8s.io/docs/start/)ローカルでテストします。
* [サービス アカウント](https://developer.1password.com/docs/service-accounts/get-started/)または[Connect サーバー](https://developer.1password.com/docs/connect/get-started/#step-2-deploy-1password-connect-server)として Secrets Automation ワークフローをCreateします。

### **Limitations** <a href="#e387u5p6hyhw" id="e387u5p6hyhw"></a>

Kubernetes Injector については、考慮すべき制限とニュアンスがいくつかあります。例:

* Kubernetes Injector では、commandフィールドを使うためにデプロイメント仕様が必要です。
* デフォルトでは、シークレットは全てのコンテナのセッションで使用できるわけではありません。

#### **The command field** <a href="#xo5ld3bs4961" id="xo5ld3bs4961"></a>

Kubernetes Secrets Injector は、初期化時にコマンド値を変更することで機能します。そのため、シークレットを注入するポッドには、デプロイメント仕様ファイルでコマンド値が定義されている必要があります (次のコード ブロックに示すように)。

以下のコード ブロックのコマンド フィールドを参照してください。この例では、1Password サービス アカウントは、npm start によって実行されるアプリケーションにシークレットを挿入します。

deployment-specification.yaml

spec:

containers:

\- name: app-example1

image: my-image

ports:

\- containerPort: 5000

command: \["①npm"]

args: \["②start"]

env:

\- name: OP\_SERVICE\_ACCOUNT\_TOKEN

valueFrom:

secretKeyRef:

name: op-service-account

key: token

\- name: DB\_USERNAME

value: op\://my-vault/my-item/sql/username

\- name: DB\_PASSWORD

value: op\://my-vault/my-item/sql/password

使用しているデプロイメントが、デプロイメントでコマンド フィールドが指定されるように設計されていない場合は、1Password [Kubernetes Operator が](https://developer.1password.com/docs/k8s/k8s-operator/)ユースケースに適している可能性があります。

#### **Session availability** <a href="#opq5k3qxbv7n" id="opq5k3qxbv7n"></a>

挿入されたシークレットは、現在のポッドのセッションでのみ使用できます。コンテナ仕様にリストされているコマンドのシークレットにのみアクセスできます。他のセッションでアクセスするには、例えば kubectl を使用して、コマンドの先頭に op run -- を追加する必要があります。

[サービス アカウントの例のデプロイメント仕様](https://developer.1password.com/docs/k8s/k8s-injector/#examples)では、app-example1 コンテナは、コマンドにnpm startよって実行されたセッションにDB\_USERNAMEおよび DB\_PASSWORD 値を挿入します。

コンテナの全てのセッションでシークレットを使用できるようにするもう 1 つの方法は、[Kubernetes Operator](https://developer.1password.com/docs/k8s/k8s-operator/)を使うことです。

Secrets Automation ワークフローと Kubernetes デプロイメントを使用して Kubernetes Injector を構成およびデプロイするには、次の手順に従います。

* ①[Kubernetes シークレットをCreateします。](https://developer.1password.com/docs/k8s/k8s-injector/#step-1)
* ②[シークレットの挿入を有効にします。](https://developer.1password.com/docs/k8s/k8s-injector/#step-2)
* ③[Kubernetes Secrets Injector をデプロイします。](https://developer.1password.com/docs/k8s/k8s-injector/#step-3)
* ④[デプロイメントに注釈を付けます。](https://developer.1password.com/docs/k8s/k8s-injector/#step-4)
* ⑤[リソース環境を構成します。](https://developer.1password.com/docs/k8s/k8s-injector/#step-5)
* ⑥[デプロイメントに 1Password CLI 資格情報を追加します。](https://developer.1password.com/docs/k8s/k8s-injector/#step-6)

これらのコード例で使用される文字列と変数に関する注意事項。

このページのコード例で使用されている一部の文字列は可変かつ任意です。その他の文字列は、1Password のコンテキスト内で特定の意味を持ちます。

このページのコード例で使用されている次の文字列は、1Password のコンテキスト内で非常に具体的かつハードコードされた意味を持ちます。

* OP\_CONNECT\_HOST
* OP\_CONNECT\_TOKEN
* OP\_SERVICE\_ACCOUNT\_TOKEN

このページのコード例で使用されている次の文字列は変数であり、1Password のコンテキスト内では特定の意味を持ちません。

* DB\_PASSWORD
* DB\_USERNAME

#### **Step 1: Create a Kubernetes Secret** <a href="#kog50h2wo3fu" id="kog50h2wo3fu"></a>

サービス アカウントまたは Connect サーバーの認証トークンを含む Kubernetes Secret をCreateします。

注意

Kubernetes Injector は、サービス アカウントと Connect サーバーの両方を使用して構成できます。両方を構成すると、Connect サーバーとその環境変数 (OP\_CONNECT\_HOSTおよびOP\_CONNECT\_TOKEN) が優先されます。

**Service account**

kubectlサービス アカウントのトークンを含む Kubernetes Secret をCreateするために使用します。サービス アカウント トークンは、サービス アカウントのCreateプロセス中に自動的に生Createされます。トークンを紛失した場合は、[新しいサービス アカウントをCreateする](https://developer.1password.com/docs/service-accounts/get-started/)必要があります。

次のコマンドを実行する前に、コマンド内の OP\_SERVICE\_ACCOUNT\_TOKEN を実際のトークンに置き換えるか、トークンを OP\_SERVICE\_ACCOUNT\_TOKEN という名前の環境変数としてエクスポートします。

$ kubectl create secret generic service-account --from-literal=token=OP\_SERVICE\_ACCOUNT\_TOKEN

#### **Step 2: Enable secrets injection** <a href="#mdx4ssjp52zo" id="mdx4ssjp52zo"></a>

kubectl を使用して、名前空間 (NAMESPACE) に Secrets-injection=enabled ラベルを追加してシークレット インジェクションを有効にします。 Kubernetes Injector は、カスタム名前空間を指定しない限り、デフォルトの名前空間を使用します。

$ kubectl label namespace NAMESPACE secrets-injection=enabled

#### **Step 3: Deploy the injector** <a href="#id-7ftyzm3sz8p7" id="id-7ftyzm3sz8p7"></a>

kubectl applyデプロイメント仕様ファイルに対してコマンドを使用します。手動デプロイメントを使う場合は、各デプロイメント仕様ファイルを個別に適用する必要があります。

次の例では、INJECTOR.yaml はKubernetes Injector デプロイメント仕様ファイルの名前であり、CONNECT.yamlは Connect デプロイメント仕様ファイルの名前です。

![](/files/QiKNek8WPLn2m1YoViDo)

デプロイを解除するには、kubectl delete を使用します。

![](/files/voUxmZmn9U3hvS8WyJpF)

**この例のコマンドはKubernetes InjectorとConnectのみをデプロイします。**[**アクセス許可、**](https://kubernetes.io/docs/tasks/administer-cluster/securing-a-cluster/)[**名前空間**](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/)**、**[**カスタムリソース定義（CRD）**](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/)[**など、必要になる可能性のある追加の構成は処理しません。**](https://kubernetes.io/docs/tasks/administer-cluster/securing-a-cluster/)

**ヒント**

[**1Password Secrets Injector Helm チャート**](https://developer.1password.com/docs/connect/helm/)**を使うと、Kubernetes Injector を 1 つのコマンドでデプロイおよび構成できます。**

**情報**

**Kubernetesインジェクターはウェブフックがデプロイされたとき（**[**deployment.yaml** ](https://github.com/1Password/kubernetes-secrets-injector/blob/main/deploy/deployment.yaml)**）必要な**[**TLS証明書をCreateします**](https://en.wikipedia.org/wiki/Public_key_certificate)**。クラスターから Kubernetes Injector を削除すると、TLS 証明書も自動的に削除されます。**

#### **Step 4: Annotate your deployment specification** <a href="#r2stfdhwns4p" id="r2stfdhwns4p"></a>

[Kubernetes デプロイメント仕様](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)に[operator.1password.io/inject:](http://operator.1password.io/inject:%E3%82%B7%E3%83%BC%E3%82%AF%E3%83%AC%E3%83%83%E3%83%88%E3%82%92%E5%A4%89%E6%9B%B4%E3%81%97%E3%81%A6%E6%8C%BF%E5%85%A5%E3%81%99%E3%82%8B%E3%82%B3%E3%83%B3%E3%83%86%E3%83%8A%E3%81%AE%E3%82%B3%E3%83%B3%E3%83%9E%E5%8C%BA%E5%88%87%E3%82%8A%E3%83%AA%E3%82%B9%E3%83%88%E3%81%8C%E7%B6%9A%E3%81%8D%E3%81%BE%E3%81%99%E3%80%82)の注釈を付けます。その後に、シークレットを変更して挿入するコンテナのコンマ区切りリストが続きます。

①デプロイメント仕様ファイルを編集し、次の注釈を追加します。

デプロイメント仕様.yaml

annotations:

operator.1password.io/inject: "app-example1, app-example2"

#### **Step 5: Configure the resource environment** <a href="#id-7xpwkpg4nlzq" id="id-7xpwkpg4nlzq"></a>

[秘密参照](https://developer.1password.com/docs/cli/secret-reference-syntax/)を使用して 1Password アイテムを参照する値を持つ環境変数をポッドまたは [Kubernetesのデプロイメント仕様に環境変数を追加](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)します。

①デプロイメント仕様ファイルを編集し、1Password 項目へのパスを含む環境変数を追加します。 VAULT 、 ITEM、 SECTION 、および FIELD を正しい値に置き換えてください。

![](/files/YpdmmRCTycBsmeMFu3NP)

値は、次のコード ブロックのテキストのようになります。

![](/files/2K5OLuXMaHWeH3m6Ysfu)

シークレットインジェクションを実行するには、KubernetesポッドまたはデプロイメントにサービスアカウントまたはConnectサーバーの認証トークンを提供する必要があります。

これを行う 1 つの方法は、資格情報の [KubernetesシークレットをCreate](https://kubernetes.io/docs/concepts/configuration/secret/)し、それを [Kubernetesデプロイメント仕様ファイルで参照](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)することです。

ヒント

認証トークンを環境変数としてエクスポートすると、仕様ファイルで環境変数を使用できます。

**Service account**

![](/files/j3nwzXfXmnfpWt3RAJTW)

**Connect**

![](/files/rrYqd4u1YE7Is8vvqOWB)

**Service account**

次の手順では、サービス アカウント トークンを Kubernetes デプロイメントにリンクします。

①まだCreateしていない場合は、kubectl を使用して、サービス アカウント トークン OP\_SERVICE\_ACCOUNT\_TOKEN を含む汎用 Kubernetes Secret をCreateします。

$ kubectl create secret generic service-account --from-literal=token=$OP\_SERVICE\_ACCOUNT\_TOKEN

②OP\_SERVICE\_ACCOUNT\_TOKEN という名前のサービス アカウント トークンの環境変数をデプロイメント仕様ファイルに追加します。 SECRET\_NAME をシークレットの名前に置き換え、KEY\_NAME をサービス アカウント キーの名前に置き換えます。

**deployment-specification.yaml**

**spec:**

**containers:**

**- name: app-example1**

**image: my-image**

**ports:**

**- containerPort: 5000**

**command: \["npm"]**

**args: \["start"]**

**env:**

**- name: OP\_SERVICE\_ACCOUNT\_TOKEN**

**valueFrom:**

**secretKeyRef:**

**name: SECRET\_NAME**

**key: KEY\_NAME**

### **Usage examples** <a href="#id-8yevtktog8gw" id="id-8yevtktog8gw"></a>

次の Kubernetes デプロイメント仕様ファイルは、デプロイメント ファイルがどのようになるべきかを示しています。

**Service account**

次のコード ブロックには、1Password サービス アカウントを使用してシークレットを挿入するための Kubernetes デプロイメント仕様 YAML ファイル設定の例が含まれています。この例では、Kubernetes インジェクターはAPP\_1にシークレットを挿入しますが、APP\_2には挿入しません。

デプロイメント仕様.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

name: app-example

spec:

selector:

matchLabels:

app: app-example

template:

metadata:

annotations:

operator.1password.io/inject: APP\_1

labels:

app: app-example

spec:

containers:

\- name: APP\_1

image: my-image

ports:

\- containerPort: 5000

command: \["npm"]

args: \["start"]

env:

\- name: OP\_SERVICE\_ACCOUNT\_TOKEN

valueFrom:

secretKeyRef:

name: op-service-account

key: token

\- name: DB\_USERNAME

value: op\://my-vault/my-item/sql/username

\- name: DB\_PASSWORD

value: op\://my-vault/my-item/sql/password

\- name: APP\_2

image: my-image

ports:

\- containerPort: 5000

command: \["npm"]

args: \["start"]

env:

\- name: DB\_USERNAME

value: op\://my-vault/my-item/sql/username

\- name: DB\_PASSWORD

value: op\://my-vault/my-item/sql/password

**Connect**

次のコード ブロックには、1Password Connect Server を使用してシークレットを挿入するための Kubernetes デプロイメント仕様 YAML ファイル設定の例が含まれています。この例では、Kubernetes Injector はAPP\_1にシークレットを挿入しますが、APP\_2には挿入しません。

​​デプロイメント仕様.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

name: app-example

spec:

selector:

matchLabels:

app: app-example

template:

metadata:

annotations:

operator.1password.io/inject: APP\_1

labels:

app: app-example

spec:

containers:

\- name: APP\_1

image: my-image

ports:

\- containerPort: 5000

command: \["npm"]

args: \["start"]

env:

\- name: OP\_CONNECT\_HOST

value: <http://onepassword-connect:8080>

\- name: OP\_CONNECT\_TOKEN

valueFrom:

secretKeyRef:

name: connect-token

key: token-value

\- name: DB\_USERNAME

value: op\://my-vault/my-item/sql/username

\- name: DB\_PASSWORD

value: op\://my-vault/my-item/sql/password

\- name: APP\_2

image: my-image

ports:

\- containerPort: 5000

command: \["npm"]

args: \["start"]

env:

\- name: DB\_USERNAME

value: op\://my-vault/my-item/sql/username

\- name: DB\_PASSWORD

value: op\://my-vault/my-item/sql/password


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.dxable.com/1password/kubernetes-injector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
