ConfigMaps and Secrets
ConfigMaps
- Purpose: Store configuration data in key-value pairs.
- How to Use: Create a ConfigMap and refer to it in Pods.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
config1: value1
config2: value2
- Access in Pods: As environment variables, volume mounts, or command-line arguments.
List all namespaces and its configmaps: kubectl get configmaps --all-namespaces -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name
Secrets
- Purpose: Store sensitive data like passwords and API keys.
- How to Use: Similar to ConfigMaps but base64 encoded.
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
data:
secret1: base64value1
secret2: base64value2
- Access in Pods: As environment variables or volume mounts.
Get environment variables from secret configurations:
envFrom:
- secretRef:
name: db-secret
Environment Variables
- Purpose: Store non-sensitive and sensitive configuration.
- How to Use: Declare them in the Pod specification.
env:
- name: ENV_NAME
value: env_value
- name: CONFIG_FROM_CONFIGMAP
valueFrom:
configMapKeyRef:
name: app-config
key: config1
Command Line Arguments
- Purpose: Pass runtime arguments to application.
- How to Use: Use
args
andcommand
fields in Pod spec.
command: ["my-command"]
args: ["arg1", "arg2"]
Configuring Liveness and Readiness Probes
Liveness Probe
- Purpose: Checks if the application is running; restarts if not.
- Types: HTTP GET, TCP Socket, Exec.
- How to Use:
livenessProbe:
httpGet:
path: /healthz
port: 8080
Readiness Probe
- Purpose: Checks if the application is ready to serve traffic.
- Types: Same as Liveness.
- How to Use:
readinessProbe:
httpGet:
path: /ready
port: 8080