Section 5: Application Lifecycle Management
0 / 28|1hr 31min
90. Application Lifecycle Management
91. file download
92. Rolling Upgrade ans Rollback
Rollout and Versioning
Rollout Command
> kubectl rollout status deployment [deployment name]
> kubectl rollout history []
kubectl apply
> kubectl apply -f deployment-definition.yml
파일 고치고 다시 배포
> kubectl set image deployment/myapp-deployment nginx=nginx:1.9.1
deployment "myapp-deployment" image is updated
Recreate
RollingUpdate
Upgrades
내부에 새로운 복제본 세트를 생성하고 동시에 컨테이너 배포를 시작함
롤링 업데이트 전략에 따라 이전 복제본 세트를 삭제함
> kubectl get replicasets
Rollback
배포를 통해 이전 개정으로 롤백하여 변경 사항을 취소하고 롤아웃을 실행하고 이전 버전으로 돌아감
> kubectl rollout undo [deployment/myapp-deployment]
Summarize Commands
> kubectl create -f deployment-definition.yml
> kubectl get deployments
> kubectl apply -f deployment-definition.yml
> kubectl set image [deployment/myapp-deployment] nginx=nginx:1.9.1
> kubectl rollout status [deployment/myapp-deployment]
> kubectl rollout history [deployment/myapp-deployment]
> kubectl rollout undo [deployment/myapp-deployment]
93. Practice Test - Rolling Updates and Rollbacks
Inspect the deployment and identify the current strategy
> kubectl describe deployment -> 'StrategyType'
> kubectl edit deployment [frontend] -> file edit
94. Solution - Rolling Updates and Rollbacks
95. Configure Applications
- Configuring Command and Arguments on applications
- Configuring Environment Variables
- Configuring Secrets
96. Commands
97. Commandds and Arguments
kubernetes POD에서 명령과 인수
docker run 명령에 추가되는 모든 것은 포드 정의의 "args" 속성으로 이동
> docker run --name ubuntu-sleeper ubuntu-sleeper
> docker run --name ubuntu-sleeper ubuntu-sleeper 10
pod-definition.yml
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-pod
spec:
containers:
- name: ubuntu-sleeper
image: ubuntu-sleeper
command: ["sleep2.0"]
args: ["10"]
> kubectl create -f pod-definition.yml
정의한 커맨드와 인자들은 파드가 생성되고 난 이후에는 변경될 수 없다.
참고: command 필드는 일부 컨테이너 런타임에서 entrypoint에 해당된다.
FROM Ubuntu
ENTRYPOINT ["sleep"]
CMD ["5"]
설명 | 도커 필드 이름 | 쿠버네티스 필드 이름
컨테이너에서 실행되는 커맨드 | Entrypoint | command
커맨드에 전달되는 인자들 | Cmd | arg
98. Practice Test - Commands and Arguments
> kubectl run pod webapp-green --image=[image_name] --dry-run=client -o yaml > webapp-color-green.yml
99. Solutions - Commands and Arguments (Optional)
100.
kubernetes 환경 변수 설정 방법
env는 배열이고 key-value1) Plain Key Value2) ConfigMap3) Secrets
101. Configuring ConfigMaps in Applications구성 데이터로 작업하는 방법pod 정의 파일에서 환경 변수를 설정하는 방법
1) Create ConfigMaps
imperative
> kubectl create configmap app-config --from-literal=APP_COLOR=blue --from-literal=APP_Mod=prod
declarative
> kubectl create -f
config-map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_COLOR: blue
APP_MOD: prod
> kubectl get configmaps
2) Inject into Pod
(1) ENV
envFrom:
- configMapRef:
name: app-config
(2) SINGLE ENV
env:
- name: APP_COLOR
valueFrom:
configMapKeyRef:
name: app-config
key: APP_COLOR
(3) VOLUME
volumes:
- name: app-config
-volume
configMap:
name: app-config
102. Practice Test: Environment Variables
103. Solutions - Environment Variables> kubectl get [pod_name] -o yaml > [sample_pod].yaml
104. Configure Secrets in Applications
암호나 키와 같은 민감한 정보를 저장하는데 사용됨
config와 같이 인코딩 되거나 해시된 형식으로 저장된다는 점을 제외하면 configMap과 유사함
1) Create Secret
- Imperative
> kubectl create secret generic <secret-name> --from-literal=<key>=<value>
> kubectl crreate secret generic app-secret --from-literal=DB_Host=mysql
> kubectl create secret generic <secret-name> --from-file=<path-to-file>
- Declarative
> kubectl create -f
secret-data.yaml
apiVersion: v1
kind: Secret
metadata:
name: app-secret
data:
DB_Host: mysql
DB_User: root
DB_Password: paswrd
> kuebectl create -f secret-data.yaml
인코딩된 형식으로 데이터를 저장해야함 base64
View Secrets
> kubectl get secrets
> kubectl describe secrets
> kubectl get secret app-secret -o yaml
Decode Secrets
> echo -n 'bxlzcw=' | base64 --decode
2) Inject into Pod
(1) ENV
envFrom:
- secretRef:
name: app-secret
(2) SINGLE ENV
env:
- name: DB_Password
valueFrom:
secretKeyRef:
name: app-secret
key: DB_Password
(3) VOLUME
volumes:
- name: app-secret-volume
secret:
secretName: app-secret
105. A note about Secrets!
106. Practice Test - Secrets
107. Solution - Secrets (Optional)
108. Scale Applications
109. Multi Container PODs
LOG Agent / WEB Server
- Create
spec:
containers:
- name: ==> array 단일 포드에서 여러 컨테이너를 허용하기 때문에 배열
110. Practice Test - Multi Container PODs
> kubectl -n elastic-stack exec -it app cat /log/app.log
apiVersion: v1
kind: Pod
metadata:
name: app
namespace: elastic-stack
labels:
name: app
spec:
containers:
- name: app
image: kodekloud/event-simulator
volumeMounts:
- mountPath: /log
name: log-volume
- name: sidecar
image: kodekloud/filebeat-configured
volumeMounts:
- mountPath: /var/log/event-simulator/
name: log-volume
volumes:
- name: log-volume
hostPath:
# directory location on host
path: /var/log/webapp
# this field is optional
type: DirectoryOrCreate
111. Solutioin - Multi Container PODs
한번 더 체크해서 보기
112. Multi-container PODs Design Patterns
CKA 에서는 필요없는 부분
113. InitContainers
114. Practice Test - InitContainers
115. Solution - InitContainers (Optional)
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
116. Self Healing Applications
CKA 필요없는 부분
117. If you like it, Share it!
'자격증 > CKA' 카테고리의 다른 글
CKA - Section 6: Cluster Maintenance (0) | 2021.03.17 |
---|---|
CKA - Section 4: Logging & Monitoring (0) | 2021.03.05 |
CKA - Section 3: Scheduling (0) | 2021.03.02 |
CKA - Section 2: Core Concepts (0) | 2021.02.16 |