(CKA) 04. Application Lifecycle Management

CKA를 준비하면서 공부한 요약 내용입니다.

Rollout and Versioning

img-1

Rollout Command

  • kubectl rollout status deployment/myapp-deployment
  • kubectl rollout history deployment/myapp-deployment

Deployment Strategy

Recreate

img-2

  • destruction 5
  • create 5

img-3

Rolling Update

→ default strategy

img-4

  • destruction and create one by one

Revision

  • kubectl apply -f deployment.yaml
  • kubectl set image deployment/myapp-deployment nginx=nginx:1.9.1

Upgrades

img-5

  • make new replicaset when upgrade deploy

Rollback

img-6

  • kubectl rollout undo deployment/myapp-deployment
  • before rollback vs after rollback img-7

Commands and Arguments

  • docker

    1
    2
    3
    
    From Ubuntu
    Entrypoint ["sleep"]
    cmd ["5"]
    
  • definition

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    apiVersion: v1
    kind: Pod
    metadata:
      name: ubuntu-sleeper-pod
    spec:
      containers:
        - name: ubuntu-sleeper
          image: ubuntu-sleeper
          command: ["sleep2.0"]
          args: ["10"]
    

Environment

  • plain Key Value

    1
    2
    3
    
    env:
      - name: APP_COLOR
        value: pink
    
  • configMap

    1
    2
    3
    4
    
    env:
      - name: APP_COLOR
        valueFrom:
          configMapKeyRef:
    
  • Secrets

    1
    2
    3
    4
    
    env:
      - name: APP_COLOR
        valueFrom:
          secretKeyRef:
    

ConfigMaps

  • create ConfigMap
  • Inject into pod

create

  • imperative

    1
    2
    3
    
    kubectl create configmap\\
      app-config --from-literal=APP_COLOR=blue \\
                --from-literal=APP_MODE=prod
    
    • kubectl create configmap app-config --from-file=<path-to-file>
  • declartive

    1
    2
    3
    4
    5
    6
    7
    
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: app-config
    data:
      APP_COLOR: blue
      APP_MODE: prod
    

view

  • kubectl get configmaps
  • kubectl describe configmaps

ConfigMap in Pods

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
apiVersion: v1
kind: Pod
metadata:
  name: simple-webapp-color
spec:
  containers:
    - name: simple-webapp-color
      image: simple-webapp-color
      envFrom:
        - configMapRef:
            name: app-config

Secrets

  • create secret
  • inject into pod

create

  • imperative

    1
    2
    
    kubectl create secret generic\\
      <secret-name> --from-literal=<key>=<value>
    
    • kubectl create secret <secret-name> --from-file=<path-to-file>
  • declartive

    1
    2
    3
    4
    5
    6
    7
    8
    
    apiVersion: v1
    kind: Secret
    metadata:
      name: app-secret
    data:
      DB_Host: mysql
      DB_User: root
      DB_Passwird: paswrd
    
    • data → encoded format for safe
    • echo -n 'mysql' | base64

view

  • kubectl get secrets
  • kubectl describe secrets

decode

  • echo -n 'abalksdfas=' | base54 --decode

Secrets in Pods

  • defintion

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
    apiVersion: v1
    kind: Pod
    metadata:
      name: simple-webapp-color
    spec:
      containers:
        - name: simple-webapp-color
          image: simple-webapp-color
          envFrom:
            - configMapRef:
                name: app-secret
    
  • env

    1
    2
    3
    
    envFrom:
      - secretRef:
          name: app-config
    
  • single env

    1
    2
    3
    4
    5
    6
    
    env:
      - name: DB_Password
        valueFrom:
          secretKeyRef:
            name: app-secret
            key: DB_Password
    
  • volume

    1
    2
    3
    4
    
    volumes:
    - name: app-secret-volumne
      secret:
        secretName: app-secret
    
    • inside the container
      • list
        1
        
        ls /opt/app-secret-volumes
        
      • content
        1
        
        cat /opt/app-secret-volumes/DB_Password
        

InitContainers

In multi-container pod, want to run a process that runs to completion in a container

  • initContainer

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    
    apiVersion: v1
    kind: Pod
    metadata:
      name: myapp-pod
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: busybox:1.28
        command: ['sh', '-c', 'echo The app is running! && sleep 3600']
      initContainers:
      - name: init-myservice
        image: busybox
        command: ['sh', '-c', 'git clone <some-repository-that-will-be-used-by-application> ; done;']
    
  • multiple initContainers

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    apiVersion: v1
    kind: Pod
    metadata:
      name: myapp-pod
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: busybox:1.28
        command: ['sh', '-c', 'echo The app is running! && sleep 3600']
      initContainers:
      - name: init-myservice
        image: busybox:1.28
        command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
      - name: init-mydb
        image: busybox:1.28
        command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']
    
Built with Hugo
Theme Stack designed by Jimmy