/images/avatar.png

Kubernetes Multi-Container POD

Multi-Container POD Multi-Container Lifecycle The containers of the POD have same lifecycle. pod-definition.yaml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 apiVersion: v1 kind: Pod metadata: name: simple-webapp labels: name: simple-webapp spec: containers: - name: simple-webapp image: simple-webapp ports: - containerPort: 8080 - name: log-agent image: log-agent

Kubernetes Environment Secrets

Create Secret Secret If you want to know all of Secret, see this document Imperative Values with command 1 2 3 4 5 6 7 8 # Structure kubectl create secret generic <secret-name> --from-literal=<key>=<value> \ --from-literal=<key>=<value> \ --from-literal=<key>=<value> # Example kubectl create secret generic app-secret --from-literal=DB_Host=mysql \ --from-literal=DB_User=root \ --from-literal=DB_Password=paswrd Values from file app_secret.properties 1 2 3 DB_Host: mysql DB_User: root DB_Password: paswrd 1 2 3 4 5 # Structure kubectl create secret generic <secret-name> --from-file=<path-to-file> # Example kubectl create secret generic app-secret --from-file=app_secret.

Kubernetes Environment Configmap

Create ConfigMap ConfigMap If you want to know all of ConfigMap, see this document Imperative Values with command 1 2 3 4 5 6 7 # Structure kubectl create configmap <config-name> --from-literal=<key>=<value> \ --from-literal=<key>=<value> \ --from-literal=<key>=<value> # Example kubectl create configmap app-config --from-literal=APP_COLOR=blue \ --from-literal=APP_MODE=prod Values from file app_config.properties 1 2 APP_COLOR: blue APP_MODE: prod 1 2 3 4 5 # Structure kubectl create configmap <config-name> --from-file=<path-to-file> # Example kubectl create configmap app-config --from-file=app_config.

Kubernetes Environment Variables

Docker 1 2 3 4 5 docker run -e APP_COLOR=blue simple-webapp-color docker run -e APP_COLOR=green simple-webapp-color docker run -e APP_COLOR=pink simple-webapp-color Kubernetes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 apiVersion: v1 kind: Pod metadata: name: simple-webapp-color spec: containers: - name: simple-webapp-color image: simple-webapp-color ports: - containerPort: 8080 env: - name: APP_COLOR value: pink

Kubernetes Application Commands

Docker Command 1 docker run ubuntu sleep 5 Dockerfile 1 2 3 4 5 6 7 8 FROM ubuntu:latest # Correct CMD sleep 5 CMD ["sleep", "5"] # Incorrect # CMD ["sleep 5"] Dockerfile and Command CMD 1 2 3 FROM ubuntu:latest CMD sleep 5 1 docker build -t ubunut-cmd-sleeper . 1 2 3 4 5 # sleep 5 docker run ubuntu-cmd-sleeper # sleep 10 docker run ubuntu-cmd-sleeper sleep 10 ENTRYPOINT 1 2 3 FROM ubuntu:latest ENTRYPOINT ["sleep"] 1 docker build -t ubuntu-entrypoint-sleeper .

Kubernetes Rolling Updates and Rollbacks

Rollout and Versioning What's the Version? The Version is a image version of the container. For example, nginx:1.7.0 to nginx:1.7.1 Rollout Commands Rollout Status 1 kubectl rollout status deployment/myapp-deployment Rollout History 1 kubectl rollout history deployment/myapp-deployment Deployment Strategy Let's assume You need to upgrade nginx:1.7.0 to nginx:1.7.1 now. Recreate Recreate Delete all application and create all application at a time. So, during the time, users cannot access the application. Rolling Update Rolling Update Delete a few PODs and create a few PODs at a time.