Prompt

How do I store API keys securely in Kubernetes? Give me the simplest workable setup.

Technology / Cybersecurity1 observationLast seen Oct 25, 2026

Latest observation

Oct 25, 2026OpenAI APIWeb search: off

The simplest workable setup is:

  1. Put the key in a Kubernetes Secret
  2. Mount it into the pod as an environment variable or file
  3. Restrict access to the Secret with RBAC
  4. Avoid committing the Secret manifest to git in plain text

That’s the basic minimum. Here’s a practical setup.


1) Create a Secret

Option A: from literal value

kubectl create secret generic api-key-secret \
  --from-literal=API_KEY='your-real-api-key'

Option B: from a file

kubectl create secret generic api-key-secret \
  --from-file=api-key.txt=./api-key.txt

Kubernetes stores Secrets base64-encoded, not encrypted by default. That’s okay for a simple setup, but not truly “secure” unless you also enable encryption at rest in the cluster.


2) Use it in a Pod

As an environment variable

apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
    - name: app
      image: nginx
      env:
        - name: API_KEY
          valueFrom:
            secretKeyRef:
              name: api-key-secret
              key: API_KEY

Or as a mounted file

apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
    - name: app
      image: nginx
      volumeMounts:
        - name: secret-volume
          mountPath: /etc/secrets
          readOnly: true
  volumes:
    - name: secret-volume
      secret:
        secretName: api-key-secret

If you mounted from a file-based secret, the app can read /etc/secrets/api-key.txt.


3) Keep the Secret out of git

If you manage manifests in Git, don’t store the raw secret YAML in the repo unless you encrypt it first.

Simplest safe-ish workflow

  • Keep the kubectl create secret ... command in your deployment docs or script
  • Apply it separately from the app manifest

If you must store it in git, use one of:

  • SOPS
  • Sealed Secrets
  • External Secrets Operator

But those are extra tooling; for the simplest workable setup, just don’t commit the secret value.


4) Use RBAC to limit access

Make sure only the app’s service account and admins can read the Secret.

Example Role allowing read of just that secret:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: read-api-key-secret
rules:
  - apiGroups: [""]
    resources: ["secrets"]
    resourceNames: ["api-key-secret"]
    verbs: ["get"]

Bind it to a service account:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: app-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: app-read-secret
subjects:
  - kind: ServiceAccount
    name: app-sa
roleRef:
  kind: Role
  name: read-api-key-secret
  apiGroup: rbac.authorization.k8s.io

Then use the service account in your pod:

spec:
  serviceAccountName: app-sa

5) The minimum “secure enough” cluster setting: encryption at rest

By default, Secret data is only base64-encoded in etcd. Enable encryption at rest for Kubernetes Secrets if possible. That’s a cluster-admin setting.

If you don’t control the cluster, at least confirm your provider supports it and it’s enabled.


Practical recommendation

If you want the simplest workable setup with decent security:

  • Create a Kubernetes Secret
  • Mount it as an env var or file
  • Don’t commit secret values to git
  • Use RBAC to limit who can read it
  • Enable secret encryption at rest if your cluster supports it

Example end-to-end

kubectl create secret generic api-key-secret \
  --from-literal=API_KEY='your-real-api-key'
apiVersion: v1
kind: ServiceAccount
metadata:
  name: app-sa
---
apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  serviceAccountName: app-sa
  containers:
    - name: app
      image: nginx
      env:
        - name: API_KEY
          valueFrom:
            secretKeyRef:
              name: api-key-secret
              key: API_KEY

If you want, I can also give you the simplest “production-ish” version using SOPS or External Secrets.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.