Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

docs: revamp Kubernetes Operator guide

Jake Hulbergadbe31e5341a
diff --git a/docs/documentation/guides/kubernetes-operator.mdx b/docs/documentation/guides/kubernetes-operator.mdx
index fc42b8d2f2..dde9430039 100644
--- a/docs/documentation/guides/kubernetes-operator.mdx
+++ b/docs/documentation/guides/kubernetes-operator.mdx
@@ -1,239 +1,621 @@
---
-title: "Managing Secrets With Kubernetes Operator"
+title: "Manage secrets with the Kubernetes Operator"
sidebarTitle: "Kubernetes Operator"
-description: "How to use the Infisical Kubernetes Operator to Push Secrets, Pull Secrets, and Generate Dynamic Secrets within your clusters."
+description: "Learn how to pull, push, and generate dynamic secrets in Kubernetes with the Infisical Operator."
---
-Infisical's Kubernetes Operator provides a seamless, secure, and automated way to synchronize secrets between your Infisical instance and your Kubernetes clusters. The Operator's three Custom Resource Definitions (CRDs) make this possible. In this guide, we provide the necessary CRDs and configurations for your kubernetes cluster, but you can customize them to fit your use-case.
+In this tutorial, you will:
-In this guide, we'll walk through how to:
+- Install the Infisical Kubernetes Operator and authenticate it with Kubernetes Auth.
+- Pull a secret from Infisical into your cluster with the `InfisicalSecret` CRD and consume it from a demo app.
+- Push a Kubernetes Secret back to Infisical with the `InfisicalPushSecret` CRD.
+- Generate a dynamic database credential in your cluster with the `InfisicalDynamicSecret` CRD.
-1. **Install the Infisical Operator on your Kubernetes cluster**.
-2. **Configure Authentication using Kubernetes Service Accounts**.
-3. **Use Each of the three CRDs**.
- - **InfisicalSecret** [Sync secrets from Infisical to Kubernetes]
- - **InfisicalPushSecret** [Sync secrets from Kubernetes to Infisical]
- - **InfisicalDynamicSecret** [Manage Dynamic Secrets and automatically create time-bound leases]
+<Note>
+ This tutorial uses the `v1alpha1` CRDs (`InfisicalSecret`, `InfisicalPushSecret`, `InfisicalDynamicSecret`), which are current and fully supported. The operator also ships a newer `v1beta1` model (`InfisicalConnection`, `InfisicalAuth`, `InfisicalStaticSecret`) that decouples connection and authentication from the synced resource. To explore it, see the [Kubernetes Operator overview](/integrations/platforms/kubernetes/overview). This tutorial teaches the `v1alpha1` path end to end.
+</Note>
## Prerequisites
-Before we begin, make sure your environment is ready
-1. Installed tools
- - [helm](https://helm.sh/docs/intro/install/), [git](https://git-scm.com/downloads), [kubectl](https://kubernetes.io/docs/tasks/tools/)
-2. Kubernetes Cluster
- - Ensure you have access to a running cluster and connect with kubectl
-3. PostgreSQL Cluster (for InfisicalDynamicSecret)
- - Ensure you have a running database that you have access to
-4. Clone [infisical-guides-source-code](https://github.com/Infisical/infisical-guides-source-code) repository
-5. Access to an Infisical instance (cloud or self-hosted)
+Before you begin, make sure you have:
-## Step-By-Step Guide
-<Steps titleSize="h2">
+- [helm](https://helm.sh/docs/intro/install/), [kubectl](https://kubernetes.io/docs/tasks/tools/), and [jq](https://jqlang.github.io/jq/download/) installed.
+- Access to a running Kubernetes cluster that `kubectl` is pointed at. Confirm with `kubectl cluster-info`.
+- Access to an Infisical instance, either [Infisical Cloud](/documentation/getting-started/overview) or a [self-hosted instance](/self-hosting/overview).
+- A running PostgreSQL database for the dynamic-secret step. The database must be network-reachable from your Infisical instance, not from your cluster. If you use Infisical Cloud, a database on your laptop or inside your cluster is not reachable, use a database with a public or peered address. If you self-host Infisical, the database must be reachable from wherever Infisical runs.
+<Info>
+ Dynamic Secrets are available under the **Pro Tier** and **Enterprise Tier** on Infisical Cloud.
+
+ If you're self-hosting Infisical, contact [email protected] to purchase an
+ enterprise license.
+</Info>
+
+## Set up the operator and authentication
+
+<Steps titleSize="h3">
<Step title="Install the Infisical Operator">
+ The [Infisical Operator](/integrations/platforms/kubernetes/overview) runs inside your cluster and reconciles the secret-synchronization resources you create.
+
+ ```bash
+ helm repo add infisical-helm-charts 'https://dl.cloudsmith.io/public/infisical/helm-charts/helm/charts/'
+ helm repo update
+ helm install infisical-operator infisical-helm-charts/secrets-operator
+ ```
-The [Infisical Operator](https://infisical.com/docs/integrations/platforms/kubernetes/overview) runs inside your cluster and is responsible for handling secret synchronization events.
-
-```console
-helm repo add infisical-helm-charts 'https://dl.cloudsmith.io/public/infisical/helm-charts/helm/charts/'
-helm repo update
-helm install infisical-operator infisical-helm-charts/secrets-operator
-```
-
-Verify the operator pod is running:
-
-```console
-kubectl get pods -n default
-```
- </Step>
- <Step title="Create a Machine Identity and Set Up a Project">
-
-The operator uses a [Machine Identity](https://infisical.com/docs/documentation/platform/identities/machine-identities) to authenticate with Infisical through the Kubernetes Auth Method
-1. Login to [Infisical](https://app.infisical.com/)
-2. Select **Organization Access** from the left navigational pane
-3. Create an Identity and give it a name and a role
-4. Once the Machine Identity is created, copy the **Identity ID** (will be used later)
-5. Select the created Machine Identity, and add a [Kubernetes Authentication Method](https://infisical.com/docs/documentation/platform/identities/kubernetes-auth). Use these configurations:
- - **Allowed Service Account Names**: infisical-service-account, default
- - **Allowed Namespaces**: default
- - **Kubernetes Host URL** can be found by running ```kubectl cluster-info```
- - **Token Reviewer JWT / CA Certificate**: We will be generating these two later and adding them in later, leave it blank for now
-6. Once the Machine Identity has been created, navigate back to **Overview**
-7. Now select **Add New Project**
- - Add a **Project Name**, and select **Secrets Management** as the product type
- - Add a description (Optional).
-8. Once the Project is created, navigate into the Project to **Add Secrets**. You can add any key-value pair for this example, however if you want to use the InfisicalSecret CRD example provided in this demo, use the following configurations:
- - **Key**: SMTP_HOST
- - **Value**: [email protected]
- - **Tags**: N/A (Not needed for this demonstration)
- - **Environments**: Production
-9. Now lets navigate to the **Project Access** tab on the left hand navigation pane.
- - Add the machine identity we created, and give it Admin permissions (just for demonstration purposes)
-
-
- </Step>
- <Step title="Set Up RBAC, Service Accounts, and Create Tokens">
-
-Now we will be interacting with the local repository you cloned earlier. Make sure you are in the directory that contains the yaml configurations. Assuming you are in your root user directory:
-
-```console
-cd infisical-guides-source-code/kubernetes-operator-demo
-```
-
-1. Create the ```infisical-token-reviewer``` service account. This Manifest creates a **service account** that the Infisical Operator uses to authenticate with Kubernetes for token reviews. It allows Infisical to validate Kubernetes tokens securely during the Machine Identity authentication process.
-```console
-kubectl apply -f infisical-reviewer-service-account.yaml
-```
-2. Create the token for the reviewer service account. This Yaml defines a **service account token secret** linked to the reviewer account created above. It generates a JWT token that Infisical uses for the Kubernetes Auth Method in your Machine Identity configuration.
-```console
-kubectl apply -f service-account-reviewer-token.yaml
-```
-3. This file binds the ```infisical-token-reviewer``` service account to the built-in ```system:auth-delegator``` ClusterRole. That role allows the service account to perform **token review** and **authentication delegation** requests on behalf of other service accounts - a key part of Kubernetes-based identity verification. Without this binding, the Infisical Operator wouldn't have permission to validate tokens.
-```console
-kubectl apply -f cluster-role-binding.yaml
-```
-4. Create the service account that will be used by the InfisicalSecret. This file creates a **dedicated service account** ```infisical-service-account``` that the Infisical Operator uses to access and sync secrets within your cluster. It operates as the Operator's working identity in your cluster, separate from the token reviewer.
-```console
-kubectl apply -f infisical-service-account.yaml
-```
-5. Create the token for the Infisical service account. This manifest defines a **token secret** for the ```infisical-service-account```. It allows the Infisical operator to authenticate against Infisical's API when syncing secrets. The token will then be manually patched and associated with the service account to make sure Kubernetes mains it persistently.
-```console
-kubectl apply -f infisical-service-account-token.yaml
-```
-6. Apply the patch to manually associate the token secret
-```console
-kubectl patch serviceaccount infisical-service-account -p '{"secrets": [{"name": "infisical-service-account-token"}]}' -n default
-```
-7. Create the **JWT Token** and **Certificate** and add it to the **Machine Identity** we created under **Kubernetes Auth**. For the generated CA, navigate to the **Advanced** tab to paste the certificate:
-- JWT Command
-```console
-kubectl get secret infisical-token-reviewer-token -n default -o jsonpath='{.data.token}' | base64 -d
-```
-
-- CA Command
-```console
-kubectl get secret infisical-token-reviewer-token -n default -o jsonpath='{.data.ca\.crt}' | base64 -d
-```
- </Step>
- <Step title="Verify Service Accounts and Tokens">
-
-1. Check to see if the service accounts were created
-
-```console
-kubectl get serviceaccount -n default | grep infisical
-```
-
-2. Verify the tokens were created and linked
-
-```console
-kubectl get secrets -n default | grep infisical
-```
- </Step>
- <Step title="Create the InfisicalSecret CRD">
-
-The [InfisicalSecret](https://infisical.com/docs/integrations/platforms/kubernetes/infisical-secret-crd) CRD tells the operator to sync secrets from Infisical to Kubernetes. By referencing your ```identityID```, ```projectSlug```, and ```envSlug```, this CRD tells the Infisical Operator which Infisical secrets to fetch and how to format them into a Kubernetes Secret. Make sure to edit the provided CRD to match your specific Machine Identity ID, Project ID, and which environment your secrets are being pulled from (default is prod).
- - **Project Slug**: Can be found when you select your project and navigate to settings
- - **Identity ID**: Can be found when you select your machine identity from your organization's access control
-
-1. After editing the ```example-infisical-secret-crd.yaml``` to contain your demo-specific values, apply the yaml in your cluster
-```console
-kubectl apply -f example-infisical-secret-crd.yaml
-```
-
- </Step>
- <Step title="Verify the InfisicalSecret Status">
-
-1. Check that the ```InfisicalSecret``` was created successfully
-```console
-kubectl get infisicalsecret -n default
-```
-2. Check that the operator created the ```managed-secret```
-```console
-kubectl get secret managed-secret -n default
-```
-3. View the secret contents (base64 encoded)
-```console
-kubectl get secret managed-secret -n default -o jsonpath='{.data}' | jq
-```
- </Step>
- <Step title="Deploy the Demo Application">
-
-1. Deploy the nginx demo deployment that will use the managed secret.
-```console
-kubectl apply -f demo-deployment.yaml
-```
-2. Wait 15-20 seconds and then verify the deployments
-```console
-kubectl get deployments
-kubectl get pods -l app=nginx
-```
+ Confirm the operator pod is running:
+
+ ```bash
+ kubectl get pods -n default
+ ```
+
+ You should see a pod whose name begins with `infisical-opera-controller-manager-` in the `Running` state with `1/1` ready:
+
+ ```
+ NAME READY STATUS RESTARTS AGE
+ infisical-opera-controller-manager-xxxxxxxxxx-xxxxx 1/1 Running 0 30s
+ ```
+
+ <Note>
+ The exact pod name is derived from the Helm release name and chart name and is truncated to 15 characters, so `infisical-operator` plus `secrets-operator` becomes the `infisical-opera` prefix. If you ran `helm install` with a different release name, your prefix will differ accordingly.
+ </Note>
+
+ <Note>
+ `helm install` uses your current kubeconfig namespace. This tutorial checks the `default` namespace throughout. If the pod does not appear under `-n default`, run `kubectl get pods -A | grep infisical` to find the namespace it landed in, and adjust the `-n` flag in later commands to match.
+ </Note>
+ </Step>
+
+ <Step title="Create a Machine Identity">
+ The operator authenticates to Infisical with a [Machine Identity](/documentation/platform/identities/machine-identities) using the [Kubernetes Auth method](/documentation/platform/identities/kubernetes-auth).
+
+ 1. Log in to [Infisical](https://app.infisical.com/).
+ 2. Select **Organization Access** from the left navigation pane.
+ 3. Create an identity, give it a name, and assign it a role.
+ 4. Copy the **Identity ID** and record it. You will paste it into every CRD as `identityId`.
+ 5. Select the identity, then add a **Kubernetes Auth** method with these values:
+ - **Allowed Service Account Names**: `infisical-service-account, default`
+ - **Allowed Namespaces**: `default`
+ - **Kubernetes Host URL**: the URL printed by `kubectl cluster-info`
+ - **Token Reviewer JWT** and **CA Certificate**: leave both blank for now. You generate these in the next steps and return to paste them in. The **CA Certificate** field is on the **Advanced** tab.
+
+ <Note>
+ You will return to this Kubernetes Auth method in the "Wire up the Kubernetes Auth method" step to paste the Token Reviewer JWT and CA certificate. Authentication does not work until you do.
+ </Note>
</Step>
- <Step title="Verify the Secret is Injected Into the Pod">
-1. Check that the environment variable is in the running pod. If everything was successful, at this point you should be able to see the secret populate in the kubernetes pod and have a successful **sync** from Infisical to Kubernetes.
-```console
-kubectl exec -it $(kubectl get pod -l app=nginx -o jsonpath='{.items[0].metadata.name}') -- env | grep SMTP
-```
- </Step>
- <Step title="Create a Kubernetes Secret to Push Up to Infisical">
-
-Now that we have successfully synced secrets from Infisical to Kubernetes, lets explore how we can push **Kubernetes Secrets** to Infisical.
-
- 1. Either create a **Kubernetes Secret** via yaml, or use the one in the repository.
-```console
-kubectl apply -f source-secret.yaml
-```
- 2. Verify creation of the secret
-```console
-kubectl get secret push-secret-demo -n default -o yaml
-```
+ <Step title="Create a project and add a secret">
+ 1. Navigate back to **Overview** and select **Add New Project**.
+ - Enter a **Project Name** and select **Secrets Management** as the product type.
+ - Add a description (optional).
+ 2. Open the project and add a secret. Use these values so they match the `InfisicalSecret` CRD later in this tutorial:
+ - **Key**: `SMTP_HOST`
+ - **Value**: `[email protected]`
+ - **Environment**: `Production`
+ 3. Record the **Project Slug** and confirm the environment slug. You need both to fill in the CRDs.
+ - Open **Project Settings** and find the **Slug** field. Copy it. This is the value you paste into the CRDs as `projectSlug`. It is distinct from the project name.
+ - In the project, open the environment list (Project Settings, then **Environments**). Find the slug for the **Production** environment you added the secret to. On a new project the Production environment's slug is usually `prod`, but confirm the exact value, the CRD's environment field must match it exactly or the sync pulls from the wrong environment.
+ 4. Open the **Project Access** tab and add the Machine Identity you created. Grant it Admin permissions for this tutorial.
+
+ <Note>
+ Admin is used here only to keep the tutorial simple. In production, scope the identity to the least privilege it needs.
+ </Note>
</Step>
- <Step title="Create the InfisicalPushSecret CRD">
-The [InfisicalPushSecret](https://infisical.com/docs/integrations/platforms/kubernetes/infisical-push-secret-crd) CRD tells the operator to sync secrets from Kubernetes to Infisical. Make sure you edit the CRD to include the specific **Project Slug**, and **Identity ID**. The other values present in ```example-push-secret.yaml``` should be configured based on the previously committed yaml configurations.
+ <Step title="Create service accounts, RBAC, and tokens">
+ The Kubernetes Auth method needs two Kubernetes service accounts:
+
+ - `infisical-token-reviewer`: its JWT lets the **Infisical backend** call the Kubernetes TokenReview API to validate tokens presented by the operator.
+ - `infisical-service-account`: the identity the operator presents when it authenticates to Infisical.
+
+ Create the token-reviewer service account:
+
+ ```bash
+ kubectl apply -f - <<'EOF'
+ apiVersion: v1
+ kind: ServiceAccount
+ metadata:
+ name: infisical-token-reviewer
+ namespace: default
+ EOF
+ ```
+
+ Create a long-lived token secret for it:
+
+ ```bash
+ kubectl apply -f - <<'EOF'
+ apiVersion: v1
+ kind: Secret
+ metadata:
+ name: infisical-token-reviewer-token
+ namespace: default
+ annotations:
+ kubernetes.io/service-account.name: infisical-token-reviewer
+ type: kubernetes.io/service-account-token
+ EOF
+ ```
+
+ Bind the token-reviewer service account to the built-in `system:auth-delegator` ClusterRole. This lets the Infisical backend, acting with this service account's JWT, submit TokenReview requests. Without this binding, TokenReview calls are denied.
+
+ ```bash
+ kubectl apply -f - <<'EOF'
+ apiVersion: rbac.authorization.k8s.io/v1
+ kind: ClusterRoleBinding
+ metadata:
+ name: infisical-token-reviewer-binding
+ roleRef:
+ apiGroup: rbac.authorization.k8s.io
+ kind: ClusterRole
+ name: system:auth-delegator
+ subjects:
+ - kind: ServiceAccount
+ name: infisical-token-reviewer
+ namespace: default
+ EOF
+ ```
+
+ Create the operator's working service account and its token secret:
+
+ ```bash
+ kubectl apply -f - <<'EOF'
+ apiVersion: v1
+ kind: ServiceAccount
+ metadata:
+ name: infisical-service-account
+ namespace: default
+ ---
+ apiVersion: v1
+ kind: Secret
+ metadata:
+ name: infisical-service-account-token
+ namespace: default
+ annotations:
+ kubernetes.io/service-account.name: infisical-service-account
+ type: kubernetes.io/service-account-token
+ EOF
+ ```
- 1. Apply the InfisicalPushSecret CRD provided after making the necessary changes
-```console
-kubectl apply -f example-push-secret-crd.yaml
-```
+ Associate the token secret with the service account:
- 2. Once your CRD has been configured, go back to your project within Infisical and check to see if your secrets have populated there.
+ ```bash
+ kubectl patch serviceaccount infisical-service-account \
+ -p '{"secrets": [{"name": "infisical-service-account-token"}]}' -n default
+ ```
-![secrets dashboard](../../images/push-secret.png)
+ You should see `serviceaccount/infisical-service-account patched`.
+ <Note>
+ The service-account names and namespaces above must match the **Allowed Service Account Names** (`infisical-service-account`) and **Allowed Namespaces** (`default`) you set on the Kubernetes Auth method, and the `serviceAccountRef` in the `InfisicalSecret` CRD. Do not rename them.
+ </Note>
</Step>
- <Step title="Create the InfisicalDynamicSecret CRD">
-The [InfisicalDynamicSecret](https://infisical.com/docs/integrations/platforms/kubernetes/infisical-dynamic-secret-crd) CRD allows you to sync dynamic secrets and create leases automatically in Kubernetes as native **Kubernetes Secret** resources Any Pod, Deployment, or other Kubernetes resource can make use of dynamic secrets from Infisical just like any other Kubernetes secret.
+ <Step title="Verify the service accounts and tokens">
+ Confirm the two service accounts exist:
- 1. Navigate to your Infisical **Project** and click on the dropdown next to **Add Secret**. From here you will select **Add Dynamic Secret**
- - Select **SQL Database** as the service you would like to connect to.
- - Select **PostegreSQL** as the database service. Enter in the connection details for your database, specifically the **Host**, **Port**, **User**, **Password**, and **Database Name**.
- - For the **Secret Name**, if you want to use the same name as the one in the cloned **InfisicalDynamicSecret** CRD, use the name **dynamic-secret-lease**. Otherwise you will need to change the **dynamicSecret.secretName** config in the InfisicalDynamicSecret CRD to whatever you name the secret here.
- - In the CA (SSL) section, make sure to upload the **CA Certificate** for your database.
- - Finally, select **Prod** as the environment (we are keeping this configuration as part of the demonstration).
+ ```bash
+ kubectl get serviceaccount -n default | grep infisical
+ ```
-![secrets dashboard dynamic](../../images/dynamic-secret.png)
+ You should see `infisical-token-reviewer` and `infisical-service-account`.
- 2. Edit the ```dynamic-secret-crd``` with the proper machine **Identity ID**, **Project Slug**, **dynamicSecret.secretName** (same as the **Secret Name** you gave to the dynamic secret in Infisical), and managedSecretReference.secretName (name of the kubernetes secret that Infisical Operator will create/populate in the cluster).
- - If you want to keep the **managedSecretReference.secretName** then you can leave it as **dynamic-secret-test**
+ Confirm the two token secrets exist:
- 3. Once the changes have been saved, apply the yaml:
+ ```bash
+ kubectl get secrets -n default | grep infisical
+ ```
- ```console
- kubectl apply -f dynamic-secret-crd.yaml
+ You should see `infisical-token-reviewer-token` and `infisical-service-account-token`, each of type `kubernetes.io/service-account-token`.
+ </Step>
+
+ <Step title="Wire up the Kubernetes Auth method">
+ Now retrieve the reviewer JWT and CA certificate, then paste them into the Machine Identity's Kubernetes Auth method to complete the auth loop you left open earlier.
+
+ Print the Token Reviewer JWT:
+
+ ```bash
+ kubectl get secret infisical-token-reviewer-token -n default \
+ -o jsonpath='{.data.token}' | base64 -d
```
- 4. After applying the CRD, you should notice that the dynamic secret lease has been created and synced with your cluster. Verify by running:
+ Print the cluster CA certificate:
+
+ ```bash
+ kubectl get secret infisical-token-reviewer-token -n default \
+ -o jsonpath='{.data.ca\.crt}' | base64 -d
+ ```
-```console
-kubectl get secret dynamic-secret-test -n default -o yaml
-```
+ Then, in Infisical:
- 5. Once the dynamic secret lease has been created, you should see that the secret has data that contains the lease credentials.
+ 1. Open the Machine Identity and open its **Kubernetes Auth** method for editing.
+ 2. Paste the decoded JWT into the **Token Reviewer JWT** field.
+ 3. Switch to the **Advanced** tab and paste the decoded certificate into the **CA Certificate** field.
+ 4. Save the configuration.
-![dynamic secrets output](../../images/dynamic-secret-crd.png)
+ <Info>
+ The **CA Certificate** field is optional and pairs with the **Verify TLS Certificate** toggle on the **Advanced** tab. When that toggle is on, Infisical validates the Kubernetes API server's TLS certificate against this CA. You can save with the CA left empty, but for production keep verification on and provide the cluster CA.
+ </Info>
+
+ After saving, both fields should show as populated. The Machine Identity can now authenticate operator requests.
</Step>
</Steps>
-**Congratulations! You successfully managed secrets with Kubernetes.**
\ No newline at end of file
+## Pull a secret with the InfisicalSecret CRD
+
+The [`InfisicalSecret`](/integrations/platforms/kubernetes/infisical-secret-crd) CRD tells the operator to fetch secrets from Infisical and write them into a native Kubernetes Secret.
+
+<Steps titleSize="h3">
+ <Step title="Create the InfisicalSecret resource">
+ Save the manifest below as `infisical-secret.yaml`. Replace the placeholders with the values you recorded: `your-identity-id`, `your-project-slug`, and the environment slug you confirmed (`prod` unless yours differs).
+
+ ```yaml
+ apiVersion: secrets.infisical.com/v1alpha1
+ kind: InfisicalSecret
+ metadata:
+ name: infisical-secret-demo
+ namespace: default
+ spec:
+ authentication:
+ kubernetesAuth:
+ identityId: your-identity-id
+ serviceAccountRef:
+ name: infisical-service-account
+ namespace: default
+ secretsScope:
+ projectSlug: your-project-slug
+ envSlug: prod
+ secretsPath: "/"
+ managedSecretReference:
+ secretName: managed-secret
+ secretNamespace: default
+ ```
+
+ Each recorded value maps to one field:
+
+ | Value you recorded | CRD field |
+ |---|---|
+ | Identity ID | `spec.authentication.kubernetesAuth.identityId` |
+ | Project Slug | `spec.authentication.kubernetesAuth.secretsScope.projectSlug` |
+ | Environment slug | `spec.authentication.kubernetesAuth.secretsScope.envSlug` |
+
+ <Note>
+ For `InfisicalSecret`, the environment field is `envSlug` and it lives under `secretsScope`. The `projectSlug` and `envSlug` fields are nested there, not at the top of the spec. The operator writes the fetched secrets into a Kubernetes Secret named by `managedSecretReference.secretName`, which is `managed-secret` here.
+ </Note>
+
+ Apply the resource:
+
+ ```bash
+ kubectl apply -f infisical-secret.yaml
+ ```
+ </Step>
+
+ <Step title="Verify the InfisicalSecret synced">
+ Confirm the resource exists:
+
+ ```bash
+ kubectl get infisicalsecret -n default
+ ```
+
+ Confirm the operator created the managed secret:
+
+ ```bash
+ kubectl get secret managed-secret -n default
+ ```
+
+ View the secret contents:
+
+ ```bash
+ kubectl get secret managed-secret -n default -o jsonpath='{.data}' | jq
+ ```
+
+ You should see a base64-encoded entry for `SMTP_HOST`.
+ </Step>
+
+ <Step title="Deploy a demo app that consumes the secret">
+ Save this Deployment as `demo-deployment.yaml`. It mounts `managed-secret` as environment variables into an nginx pod.
+
+ ```yaml
+ apiVersion: apps/v1
+ kind: Deployment
+ metadata:
+ name: nginx-demo
+ namespace: default
+ labels:
+ app: nginx
+ spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: nginx
+ template:
+ metadata:
+ labels:
+ app: nginx
+ spec:
+ containers:
+ - name: nginx
+ image: nginx:latest
+ envFrom:
+ - secretRef:
+ name: managed-secret
+ ```
+
+ Apply it:
+
+ ```bash
+ kubectl apply -f demo-deployment.yaml
+ ```
+
+ Wait 15 to 20 seconds, then confirm the deployment and pod are ready:
+
+ ```bash
+ kubectl get deployments -n default
+ kubectl get pods -l app=nginx -n default
+ ```
+ </Step>
+
+ <Step title="Confirm the secret reached the pod">
+ Check that the environment variable is present in the running pod:
+
+ ```bash
+ kubectl exec -it $(kubectl get pod -l app=nginx -n default -o jsonpath='{.items[0].metadata.name}') -n default -- env | grep SMTP
+ ```
+
+ You should see `[email protected]`. The pull sync from Infisical to Kubernetes now works end to end.
+ </Step>
+</Steps>
+
+## Push a secret with the InfisicalPushSecret CRD
+
+The [`InfisicalPushSecret`](/integrations/platforms/kubernetes/infisical-push-secret-crd) CRD does the reverse: it reads a Kubernetes Secret and writes its values into Infisical.
+
+<Steps titleSize="h3">
+ <Step title="Create the source Kubernetes Secret">
+ Save this as `source-secret.yaml`:
+
+ ```yaml
+ apiVersion: v1
+ kind: Secret
+ metadata:
+ name: push-secret-demo
+ namespace: default
+ type: Opaque
+ stringData:
+ API_KEY: example-value
+ ```
+
+ Apply and verify it:
+
+ ```bash
+ kubectl apply -f source-secret.yaml
+ kubectl get secret push-secret-demo -n default -o yaml
+ ```
+ </Step>
+
+ <Step title="Create the InfisicalPushSecret resource">
+ Save the manifest below as `push-secret.yaml`. Replace `your-identity-id` and `your-project-slug`, and set `environmentSlug` to the environment you want to push into (the slug you confirmed earlier).
+
+ ```yaml
+ apiVersion: secrets.infisical.com/v1alpha1
+ kind: InfisicalPushSecret
+ metadata:
+ name: push-secret-demo
+ namespace: default
+ spec:
+ updatePolicy: Replace
+ deletionPolicy: Delete
+ destination:
+ projectSlug: your-project-slug
+ environmentSlug: prod
+ secretsPath: "/"
+ authentication:
+ kubernetesAuth:
+ identityId: your-identity-id
+ serviceAccountRef:
+ name: infisical-service-account
+ namespace: default
+ push:
+ secret:
+ secretName: push-secret-demo
+ secretNamespace: default
+ ```
+
+ Note the differences from the pull CRD:
+
+ - The environment field is `environmentSlug` here, not `envSlug`.
+ - `projectSlug` and `environmentSlug` live under `spec.destination`.
+ - The Kubernetes-auth block has no `secretsScope`; it only needs `identityId` and `serviceAccountRef`.
+ - `push.secret.secretName` must match the source secret you created (`push-secret-demo`).
+
+ <Note>
+ In `spec.destination`, set exactly one of `projectSlug` or `projectId`. Setting both, or neither, is rejected by the CRD's validation.
+ </Note>
+
+ Apply the resource:
+
+ ```bash
+ kubectl apply -f push-secret.yaml
+ ```
+ </Step>
+
+ <Step title="Verify the push reached Infisical">
+ Open your project in Infisical, select the environment you pushed to, and confirm `API_KEY` now appears.
+
+ ![Infisical project secrets dashboard showing the pushed API_KEY secret](/images/push-secret.png)
+ </Step>
+</Steps>
+
+## Generate a dynamic secret with the InfisicalDynamicSecret CRD
+
+The [`InfisicalDynamicSecret`](/integrations/platforms/kubernetes/infisical-dynamic-secret-crd) CRD tells the operator to create and lease a [Dynamic Secret](/documentation/platform/dynamic-secrets/overview), then write the lease credentials into a Kubernetes Secret that any workload can consume.
+
+<Steps titleSize="h3">
+ <Step title="Create the dynamic secret in Infisical">
+ 1. In your project, open the dropdown next to **Add Secret** and select **Add Dynamic Secret**.
+ 2. Select **SQL Database**, then **PostgreSQL** as the provider.
+ 3. Enter your database's **Host**, **Port**, **User**, **Password**, and **Database Name**. The database must be network-reachable from your Infisical instance, as noted in the prerequisites.
+ 4. In the CA (SSL) section, upload your database's CA certificate if it enforces TLS with a custom CA. If it does not require a custom CA, leave this empty.
+ 5. Set the **Secret Name** to `dynamic-secret-lease`.
+ 6. Select the environment matching the slug you confirmed earlier.
+
+ ![Infisical add dynamic secret modal with PostgreSQL connection fields](/images/dynamic-secret.png)
+ </Step>
+
+ <Step title="Create the InfisicalDynamicSecret resource">
+ Three names are in play. Keep them straight:
+
+ | Name | Where it lives | Value in this tutorial |
+ |---|---|---|
+ | Infisical dynamic secret name | Set in the Infisical UI above | `dynamic-secret-lease` |
+ | CRD `dynamicSecret.secretName` | Must equal the Infisical name | `dynamic-secret-lease` |
+ | CRD `managedSecretReference.secretName` | The Kubernetes Secret the operator creates | `dynamic-secret-test` |
+
+ The verify command reads the Kubernetes Secret, so it uses `managedSecretReference.secretName`.
+
+ Save the manifest below as `dynamic-secret.yaml`. Replace `your-identity-id` and `your-project-slug`, and set `environmentSlug` to your confirmed slug.
+
+ ```yaml
+ apiVersion: secrets.infisical.com/v1alpha1
+ kind: InfisicalDynamicSecret
+ metadata:
+ name: dynamic-secret-demo
+ namespace: default
+ spec:
+ dynamicSecret:
+ secretName: dynamic-secret-lease
+ projectSlug: your-project-slug
+ environmentSlug: prod
+ secretsPath: "/"
+ authentication:
+ kubernetesAuth:
+ identityId: your-identity-id
+ serviceAccountRef:
+ name: infisical-service-account
+ namespace: default
+ managedSecretReference:
+ secretName: dynamic-secret-test
+ secretNamespace: default
+ leaseRevocationPolicy: Revoke
+ leaseTTL: "1h"
+ ```
+
+ Note for this CRD:
+
+ - The environment field is `environmentSlug`, and `projectSlug`/`environmentSlug`/`secretsPath` live under `spec.dynamicSecret`.
+ - `leaseRevocationPolicy: Revoke` revokes the lease when you delete the resource, which matters for cleanup. Omit it to leave leases in place.
+ - `leaseTTL` is optional and defaults to the dynamic secret's own TTL if omitted.
+
+ Apply the resource:
+
+ ```bash
+ kubectl apply -f dynamic-secret.yaml
+ ```
+ </Step>
+
+ <Step title="Verify the lease was created">
+ Confirm the operator created the Kubernetes Secret holding the lease credentials:
+
+ ```bash
+ kubectl get secret dynamic-secret-test -n default -o yaml
+ ```
+
+ The `data` section should contain the generated database username and password for the lease. If you renamed `managedSecretReference.secretName`, substitute that name in the command above.
+
+ ![Kubernetes Secret containing the generated dynamic secret lease credentials](/images/dynamic-secret-crd.png)
+ </Step>
+</Steps>
+
+## Verify the result
+
+Confirm all three workflows succeeded:
+
+- **Pull**: `kubectl exec -it $(kubectl get pod -l app=nginx -n default -o jsonpath='{.items[0].metadata.name}') -n default -- env | grep SMTP` prints `[email protected]`.
+- **Push**: `API_KEY` appears in your Infisical project's environment.
+- **Dynamic**: `kubectl get secret dynamic-secret-test -n default -o jsonpath='{.data}' | jq` shows lease credentials.
+
+If all three checks pass, you have synced secrets in both directions and generated a leased database credential from Kubernetes.
+
+## Troubleshooting
+
+If a sync does not produce the expected result, inspect the resource's status conditions and the operator logs before changing anything.
+
+<AccordionGroup>
+ <Accordion title="The managed secret is missing or the InfisicalSecret is not syncing">
+ Describe the resource and read its conditions:
+
+ ```bash
+ kubectl describe infisicalsecret infisical-secret-demo -n default
+ ```
+
+ The operator sets these conditions on an `InfisicalSecret`:
+
+ - `secrets.infisical.com/LoadedInfisicalToken`: `False` means the operator could not authenticate. This is the most common failure when the **Token Reviewer JWT** or **CA Certificate** were not pasted back into the Kubernetes Auth method, or the service-account names do not match the Allowed Service Account Names.
+ - `secrets.infisical.com/ReadyToSyncSecrets`: `False` means authentication succeeded but the secrets could not be fetched, often a wrong `projectSlug` or `envSlug`.
+
+ Then check the operator logs:
+
+ ```bash
+ kubectl logs -l control-plane=controller-manager -n default
+ ```
+
+ The two most common causes are: authentication not fully wired (revisit "Wire up the Kubernetes Auth method"), and an environment slug that does not match the environment holding your secret (revisit "Create a project and add a secret").
+ </Accordion>
+ <Accordion title="The push to Infisical did not appear">
+ Describe the push resource:
+
+ ```bash
+ kubectl describe infisicalpushsecret push-secret-demo -n default
+ ```
+
+ Check the `secrets.infisical.com/Authenticated` and `secrets.infisical.com/Reconcile` conditions. A failed `Reconcile` means the secrets were not pushed; the condition message names the error. Confirm `push.secret.secretName` matches an existing Kubernetes Secret and that `destination.projectSlug` and `destination.environmentSlug` are correct.
+ </Accordion>
+ <Accordion title="The dynamic secret lease was not created">
+ Describe the dynamic-secret resource:
+
+ ```bash
+ kubectl describe infisicaldynamicsecret dynamic-secret-demo -n default
+ ```
+
+ The operator sets `secrets.infisical.com/Authenticated`, `secrets.infisical.com/LeaseCreated`, and `secrets.infisical.com/LeaseRenewal`. A failed `LeaseCreated` usually means Infisical could not reach your PostgreSQL database or the connection credentials are wrong. Confirm the database is reachable from your Infisical instance and that the connection details entered in the UI are correct.
+ </Accordion>
+</AccordionGroup>
+
+## Clean up
+
+Remove the resources this tutorial created so you do not leave an active database lease or orphaned objects behind.
+
+1. Delete the CRDs. Deleting the `InfisicalDynamicSecret` with `leaseRevocationPolicy: Revoke` revokes the active database lease.
+
+ ```bash
+ kubectl delete infisicaldynamicsecret dynamic-secret-demo -n default
+ kubectl delete infisicalpushsecret push-secret-demo -n default
+ kubectl delete infisicalsecret infisical-secret-demo -n default
+ ```
+
+2. Delete the demo app and secrets:
+
+ ```bash
+ kubectl delete deployment nginx-demo -n default
+ kubectl delete secret managed-secret dynamic-secret-test push-secret-demo -n default
+ ```
+
+3. Delete the service accounts, their token secrets, and the ClusterRoleBinding:
+
+ ```bash
+ kubectl delete secret infisical-token-reviewer-token infisical-service-account-token -n default
+ kubectl delete serviceaccount infisical-token-reviewer infisical-service-account -n default
+ kubectl delete clusterrolebinding infisical-token-reviewer-binding
+ ```
+
+4. Uninstall the operator:
+
+ ```bash
+ helm uninstall infisical-operator
+ ```
+
+5. In Infisical, delete the dynamic secret, the demo Machine Identity, and the demo Project if you no longer need them.
+
+## Next steps
+
+- [InfisicalSecret CRD reference](/integrations/platforms/kubernetes/infisical-secret-crd)
+- [InfisicalPushSecret CRD reference](/integrations/platforms/kubernetes/infisical-push-secret-crd)
+- [InfisicalDynamicSecret CRD reference](/integrations/platforms/kubernetes/infisical-dynamic-secret-crd)
+- [Kubernetes Auth for Machine Identities](/documentation/platform/identities/kubernetes-auth)