1. How many PODs exist on the system? In the current(default) namespace.
$ controlplane ~ ➜ k get pods
No resources found in default namespace.
answer : 0
2. How many ReplicaSets exist on the system? In the current(default) namespace
$ controlplane ~ ➜ k get replicasets.apps
No resources found in default namespace.
answer : 0
3. How about now? How many ReplicaSets do you see? We just made a few changes!
$ controlplane ~ ➜ k get replicasets.apps
NAME DESIRED CURRENT READY AGE
new-replica-set 4 4 0 14s
answer : 1
4. How many PODs are DESIRED in the new-replica-set?
# 위 get 커맨드 참조
answer : 4
5. What is the image used to create the pods in the new-replica-set?
$ controlplane ~ ➜ k describe replicasets new-replica-set
.... 중략
Pod Template:
Labels: name=busybox-pod
Containers:
busybox-container:
Image: busybox777
...
answer : busybox777
6. How many PODs are READY in the new-replica-set?
# 4번 문제 참조
answer : 0
7. Why do you think the PODs are not ready?
# 이미지 이름이 잘못되었음.
answer : The image BUSYBOX777 doesn't exist.
8. Delete any one of the 4 PODs.
$ controlplane ~ ✖ k get pods
NAME READY STATUS RESTARTS AGE
new-replica-set-bt8fl 0/1 ImagePullBackOff 0 4m13s
new-replica-set-9rv8g 0/1 ImagePullBackOff 0 4m13s
new-replica-set-nsvmd 0/1 ImagePullBackOff 0 4m13s
new-replica-set-x8mtd 0/1 ImagePullBackOff 0 4m13s
$ controlplane ~ ➜ k delete pods new-replica-set-bt8fl
pod "new-replica-set-bt8fl" deleted
$ controlplane ~ ➜ k delete pods new-replica-set-9rv8g
pod "new-replica-set-9rv8g" deleted
$ controlplane ~ ➜ k delete pods new-replica-set-nsvmd
pod "new-replica-set-nsvmd" deleted
$ controlplane ~ ➜ k delete pods new-replica-set-x8mtd
pod "new-replica-set-x8mtd" deleted
9. How many PODs exist now?
$ controlplane ~ ➜ k get pods
NAME READY STATUS RESTARTS AGE
new-replica-set-9rv8g 0/1 ImagePullBackOff 0 5m48s
new-replica-set-nsvmd 0/1 ImagePullBackOff 0 5m48s
new-replica-set-x8mtd 0/1 ImagePullBackOff 0 5m48s
new-replica-set-2cnlz 0/1 ImagePullBackOff 0 89s
answer : 4
10. Why are there still 4 PODs, even after you deleted one?
Replicasets 로 생성된 POD 라서 지워도 다시 생성된다.
answer : ReplicaSet ensures that desired number of PODs always run
11. Create a ReplicaSet using the replicaset-definition-1.yaml file located at /root/.
There is an issue with the file, so try to fix it.
- k8s DOCs
https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#how-a-replicaset-works
$ vi replicaset-definition-1.yaml
## yaml
apiVersion: v1 ## -> apps/v1 로 수정해야함.
kind: ReplicaSet
metadata:
name: replicaset-1
spec:
replicas: 2
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx
controlplane ~ ➜ k apply -f replicaset-definition-1.yaml
replicaset.apps/replicaset-1 created
12.Fix the issue in the replicaset-definition-2.yaml file and create a ReplicaSet using it.
This file is located at /root/.
$ vi replicaset-definition-2.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-2
spec:
replicas: 2
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: nginx ## -> matchLabels 에 있는 label로 맞춰야함 nginx -> frontend
spec:
containers:
- name: nginx
image: nginx
controlplane ~ ➜ k apply -f replicaset-definition-2.yaml
replicaset.apps/replicaset-2 created
13. Delete the two newly created ReplicaSets - replicaset-1 and replicaset-2
$ controlplane ~ ➜ k get replicasets.apps
NAME DESIRED CURRENT READY AGE
new-replica-set 4 4 0 17m
replicaset-1 2 2 2 3m4s
replicaset-2 2 2 2 49s
$ controlplane ~ ➜ k delete replicasets.apps replicaset-1
replicaset.apps "replicaset-1" deleted
$ controlplane ~ ➜ k delete replicasets.apps replicaset-2
replicaset.apps "replicaset-2" deleted
14. Fix the original replica set new-replica-set to use the correct busybox image.
Either delete and recreate the ReplicaSet or Update the existing ReplicaSet and then delete all PODs, so new ones with the correct image will be created.
$ controlplane ~ ➜ k edit replicasets.apps new-replica-set
... 중략
spec:
containers:
- command:
- sh
- -c
- echo Hello Kubernetes! && sleep 3600
image: busybox777 ### 이미지 명 변경후 저장. busybox
imagePullPolicy: Always
name: busybox-container
resources: {}
...
replicaset.apps/new-replica-set edited
## 수정된 정보로 pod를 기동하기 위해 pod 삭제
controlplane ~ ➜ k get pods
NAME READY STATUS RESTARTS AGE
new-replica-set-x8mtd 0/1 ImagePullBackOff 0 20m
new-replica-set-nsvmd 0/1 ImagePullBackOff 0 20m
new-replica-set-9rv8g 0/1 ImagePullBackOff 0 20m
new-replica-set-2cnlz 0/1 ImagePullBackOff 0 16m
controlplane ~ ➜ k delete pods new-replica-set-x8mtd
pod "new-replica-set-x8mtd" deleted
controlplane ~ ➜ k delete pods new-replica-set-nsvmd
pod "new-replica-set-nsvmd" deleted
controlplane ~ ➜ k delete pods new-replica-set-2cnlz
pod "new-replica-set-2cnlz" deleted
controlplane ~ ➜ k delete pods new-replica-set-9rv8g
pod "new-replica-set-9rv8g" deleted
controlplane ~ ➜ k get pods
NAME READY STATUS RESTARTS AGE
new-replica-set-pmbzz 1/1 Running 0 76s
new-replica-set-zcmfh 1/1 Running 0 69s
new-replica-set-bztrv 1/1 Running 0 63s
new-replica-set-smcmr 1/1 Running 0 40s
15. Scale the ReplicaSet to 5 PODs.
Use kubectl scale command or edit the replicaset using kubectl edit replicaset.
https://kubernetes.io/docs/reference/kubectl/generated/kubectl_scale/
$ k scale replicaset --replicas=5 new-replica-set
# 또는 edit 이용
16. Now scale the ReplicaSet down to 2 PODs.
Use the kubectl scale command or edit the replicaset using kubectl edit replicaset.
$ kubectl scale rs new-replica-set --replicas=2
'IT 기술 > k8s' 카테고리의 다른 글
[cka] namespace (1) | 2024.05.28 |
---|---|
[cka] Deployments (0) | 2024.05.28 |
[cka] kodecloud PODs 생성하기. (0) | 2024.05.27 |
[k8s] kubeadm token 생성하기. (0) | 2024.05.15 |
[k8s] etcd 백업 / 복원 하기 (0) | 2024.05.09 |
댓글