Creating and testing pods

Create a dummy pod and connect to it. Using dummy.yaml from Kubernetes.
Busybox has no /bin/bash, so /bin/sh must be used.

cat pods/dummy.yaml
[..]
metadata:
   name: <name>
[..]
kubectl apply -f pods/dummy.yaml
#make sure pod is running
#wide -A: show IPs of pods/containers
kubectl get pods -o wide -A
#some information on pod
kubectl describe pods <name>
#check logs (says something like Hello Kubernets!)
kubectl logs <name>
#connect to running pod
kubectl exec --stdin --tty <name> -- /bin/sh
#stop a pod
kubectl delete pod <name>

Working with secrets

$ kubectl create secret generic labkey-db \
    --from-literal=POSTGRES_USER=X \
    --from-literal=POSTGRES_PASSWORD='X1'\
    --from-literal=POSTGRES_DB='X2'\
# check  
$ kubectl get secrets
$ kubectl describe secret labkey-db
Name:         labkey-db
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
POSTGRES_DB:        6 bytes
POSTGRES_PASSWORD:  24 bytes
POSTGRES_USER:      8 bytes
$ kubectl get secret labkey-db -o jsonpath='{.data}'
{"POSTGRES_DB":"bGFia2V5","POSTGRES_PASSWORD":"c29tZXRoaW5nU2VjcmV0LmthaGw5RXA2","POSTGRES_USER":"cG9zdGdyZXM="}
$ kubectl get secret labkey-db -o jsonpath='{.data}' | jq -r '.POSTGRES_DB' | base64 --decode
X2
#remove secred
$ kubectl delete secret labkey-db

Whole file as a configmap or a secret

To provide whole files, use --from-file when creating a configmap or a secret. See example.

$ kubectl create configmap tomcat-setenv --from-file setenv.sh 
$ kubectl create secret generic labkey-xml --from-file labkey.xml 

Files are then mounted into a pod. Also, use subPath in volumeMount to prevent kubernetes to use mount path exclusively for configmap or secret. From pod.yaml:

spec:
[..]
  contianers:
[..]
    volumeMounts:
[..]
    - mountPath: /usr/local/tomcat/conf/Catalina/localhost/labkey.xml
       name: labkey-xml
       readOnly: true
       subPath: labkey.xml
[..]
  volumes:
[..]
  - name: labkey-xml
     secret:
       secretName: labkey-xml

Use env variables when creating secrets or configmap

If your mydeploy.yaml uses env variables, you apply it via:

$ envsubst < mydeploy.yaml | kubectl apply -f 

  Attached Files  
   
 dummy.yaml

Discussion