Skip to content

Instantly share code, notes, and snippets.

@jtr109
Last active December 3, 2018 13:39
Show Gist options
  • Save jtr109/2ba143de259504e945690be3a39ca1f9 to your computer and use it in GitHub Desktop.
Save jtr109/2ba143de259504e945690be3a39ca1f9 to your computer and use it in GitHub Desktop.
Cheat Sheet of Kubernetes

ConfigMap

Usage

Create an config yaml:

# filename: db-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: db-config
  namespace: default
data:
  ENV_VAR: test
  ENV_VAR2: "123"

Ask kubectl to create from file:

$ kubectl create -f db-config.yaml

Check your configuration is applied:

$ kubectl get configmap

Edit you pod configuration or deployment:

apiVersion: v1
kind: Pod
metadata:
  name: demo-from-env
spec:
  containers:
  - name: envtest
    image: supergiantkir/k8s-liveliness
    ports:
    - containerPort: 8080
    envFrom:
    - configMapRef:
        name: db-config

Then apply your pod or deployment.

Reference

Environment Variable

Usage

# pods/inject/envars.yaml

apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: "Hello from the environment"
    - name: DEMO_FAREWELL
      value: "Such a sweet sorrow"

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment