Q1
This lab tests your skills onย upgrading a kubernetes cluster. We have a production cluster with applications running on it. Let us explore the setup first.
What is the current version of the cluster?
ํ์ด
1.
kubectl get nodes
ํ์ฌ ๋ฒ์ ์ ๋ํ ์ ๋ณด๊ฐ ์ถ๋ ฅ๋จ
controlplane ~ โ kubectl get nodes
NAME STATUS ROLES AGE VERSION
controlplane Ready control-plane 24m v1.30.0
node01 Ready <none> 23m v1.30.0
Bash
๋ณต์ฌ
2.
kubeadm upgrade plan
kubectl get nodes๋ก๋ ๋ฒ์ ์ ํ์ธํ ์ ์์ง๋ง ์ด๋ kubelet์ ๋ฒ์ ์ด์ง ํด๋ฌ์คํฐ์ ๋ฒ์ ์ด ์๋๊ธฐ ๋๋ฌธ์ ์ ํํ ํ๋จ์ ์ํด์ kubeadm upgrade plan์ผ๋ก ํ์ฌ ๋ฒ์ ํ์ธ
controlplane ~ โ kubeadm upgrade plan
...
COMPONENT NODE CURRENT TARGET
kubelet controlplane v1.30.0 v1.30.8
kubelet node01 v1.30.0 v1.30.8
...
Bash
๋ณต์ฌ
์ ๋ต
v1.30.0
Q2
How many nodes are part of this cluster?
Including controlplane and worker nodes
ํ์ด
controlplane ~ โ kubectl get nodes
NAME STATUS ROLES AGE VERSION
controlplane Ready control-plane 32m v1.30.0
node01 Ready <none> 31m v1.30.0
Bash
๋ณต์ฌ
์ ๋ต
2
Q3
How many nodes can host workloads in this cluster?
Inspect the applications and taints set on the nodes.
ํ์ด
controlplane ~ โ kubectl describe node | grep Taints
Taints: <none>
Taints: <none>
Bash
๋ณต์ฌ
์ ๋ต
2
Q4
How many applications are hosted on the cluster?
Count the number of deployments in theย defaultย namespace.
ํ์ด
controlplane ~ โ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
blue 5/5 5 5 16m
Bash
๋ณต์ฌ
์ ๋ต
1
Q5
What nodes are the pods hosted on?
ํ์ด
controlplane ~ โ kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
blue-fffb6db8d-6hpfz 1/1 Running 0 17m 10.244.0.4 controlplane <none> <none>
blue-fffb6db8d-8mw8g 1/1 Running 0 17m 10.244.1.2 node01 <none> <none>
blue-fffb6db8d-9bjzv 1/1 Running 0 17m 10.244.1.3 node01 <none> <none>
blue-fffb6db8d-9qmc7 1/1 Running 0 17m 10.244.0.5 controlplane <none> <none>
blue-fffb6db8d-q6pbh 1/1 Running 0 17m 10.244.1.4 node01 <none> <none>
Bash
๋ณต์ฌ
์ ๋ต
controlplane, node01
Q6
You are tasked to upgrade the cluster. Users accessing the applications must not be impacted, and you cannot provision new VMs. What strategy would you use to upgrade the cluster?
์ ๋ต
Upgrade one node at a time while moving the workloads to the other
Q7
What is the latest version available for an upgrade with the current version of the kubeadm tool installed?
ํ์ด
controlplane ~ โ kubeadm upgrade plan
...
Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT NODE CURRENT TARGET
kubelet controlplane v1.30.0 v1.30.8
kubelet node01 v1.30.0 v1.30.8
Upgrade to the latest version in the v1.30 series:
COMPONENT NODE CURRENT TARGET
kube-apiserver controlplane v1.30.0 v1.30.8
kube-controller-manager controlplane v1.30.0 v1.30.8
kube-scheduler controlplane v1.30.0 v1.30.8
kube-proxy 1.30.0 v1.30.8
CoreDNS v1.10.1 v1.11.1
etcd controlplane 3.5.12-0 3.5.12-0
...
Bash
๋ณต์ฌ
์ ๋ต
v1.30.8
Q8
We will be upgrading the controlplane node first. Drain the controlplane node of workloads and mark itย UnSchedulable
ํ์ด ๊ณผ์
kubectl drain controlplane --ignore-daemonsets
Bash
๋ณต์ฌ
Q9
Upgrade theย controlplaneย components to exact versionย v1.31.0
Upgrade the kubeadm tool (if not already), then the controlplane components, and finally the kubelet. Practice referring to the Kubernetes documentation page.
ํ์ด ๊ณผ์
1.
k8s ํจํค์ง ์ค์น๋ฅผ ์ํ APT Repository ์ค์
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Bash
๋ณต์ฌ
2.
์
๊ทธ๋ ์ด๋ ๋ฒ์ ๊ฒฐ์
sudo apt update
sudo apt-cache madison kubeadm
kubeadm | 1.31.4-1.1 | https://pkgs.k8s.io/core:/stable:/v1.31/deb Packages
kubeadm | 1.31.3-1.1 | https://pkgs.k8s.io/core:/stable:/v1.31/deb Packages
kubeadm | 1.31.2-1.1 | https://pkgs.k8s.io/core:/stable:/v1.31/deb Packages
kubeadm | 1.31.1-1.1 | https://pkgs.k8s.io/core:/stable:/v1.31/deb Packages
kubeadm | 1.31.0-1.1 | https://pkgs.k8s.io/core:/stable:/v1.31/deb Packages
Bash
๋ณต์ฌ
1.31.0 ๋ฒ์ ์ผ๋ก ์
๊ทธ๋ ์ด๋ ํ๋ผ๋ ๋ฌธ์ ์ด๋ฏ๋ก 1.31.0-1.1 ์ฌ์ฉ
3.
kubeadm ์
๊ทธ๋ ์ด๋
sudo apt-mark unhold kubeadm && \
sudo apt-get update && sudo apt-get install -y kubeadm='1.31.0-1.1' && \
sudo apt-mark hold kubeadm
Bash
๋ณต์ฌ
4.
plan ํ์ธ
์
๊ทธ๋ ์ด๋ ๊ฐ๋ฅ ๋ฒ์ ์ด v1.31.4๋ก ๋ณ๊ฒฝ๋จ์ ํ์ธ
sudo kubeadm upgrade plan
...
Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT NODE CURRENT TARGET
kubelet controlplane v1.30.0 v1.31.4
kubelet node01 v1.30.0 v1.31.4
Upgrade to the latest stable version:
COMPONENT NODE CURRENT TARGET
kube-apiserver controlplane v1.30.0 v1.31.4
kube-controller-manager controlplane v1.30.0 v1.31.4
kube-scheduler controlplane v1.30.0 v1.31.4
kube-proxy 1.30.0 v1.31.4
CoreDNS v1.10.1 v1.11.1
etcd controlplane 3.5.12-0 3.5.15-0
You can now apply the upgrade by executing the following command:
kubeadm upgrade apply v1.31.4
Note: Before you can perform this upgrade, you have to update kubeadm to v1.31.4.
...
Bash
๋ณต์ฌ
5.
ํด๋ฌ์คํฐ ์
๊ทธ๋ ์ด๋
v1.31.4๊น์ง ์
๊ทธ๋ ์ด๋ ๊ฐ๋ฅํ์ง๋ง ๋ฌธ์ ์ ๋ง๊ฒ v1.31.0์ผ๋ก ์
๊ทธ๋ ์ด๋
kubeadm upgrade apply v1.31.0
...
[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.31.0". Enjoy!
[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.
Bash
๋ณต์ฌ
6.
kubelet & kubectl ์
๊ทธ๋ ์ด๋
sudo apt-mark unhold kubelet kubectl && \
sudo apt-get update && sudo apt-get install -y kubelet='1.31.0-1.1' kubectl='1.31.0-1.1' && \
sudo apt-mark hold kubelet kubectl
Bash
๋ณต์ฌ
7.
kubelet ์ฌ์คํ
sudo systemctl daemon-reload
sudo systemctl restart kubelet
Bash
๋ณต์ฌ
์ฌ์คํ ํ ์๋ฃ๊น์ง ์ฝ๊ฐ์ ์๊ฐ ์์
8.
ํ์ธ
controlplane ~ โ kubectl get nodes
NAME STATUS ROLES AGE VERSION
controlplane Ready,SchedulingDisabled control-plane 62m v1.31.0
node01 Ready <none> 61m v1.30.0
Bash
๋ณต์ฌ
Documents
Q10
Mark theย controlplaneย node as "Schedulable" again
ํ์ด
kubectl uncordon controlplane
Bash
๋ณต์ฌ
Q11
Next is the worker node.ย Drainย the worker node of the workloads and mark itย UnSchedulable
ํ์ด
kubectl drain node01 --ignore-daemonsets
Bash
๋ณต์ฌ
Q12
Upgrade the worker node to the exact versionย v1.31.0
ํ์ด ๊ณผ์
1.
Drain worker node
kubectl drain node01 --ignore-daemonsets
Bash
๋ณต์ฌ
2.
node01์ ์ ์
ssh node01
Bash
๋ณต์ฌ
3.
k8s ํจํค์ง ์ค์น๋ฅผ ์ํ APT Repository ์ค์
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Bash
๋ณต์ฌ
4.
๋
ธ๋ ์
๊ทธ๋ ์ด๋
sudo kubeadm upgrade node
Bash
๋ณต์ฌ
5.
kubelet & kubectl ์
๊ทธ๋ ์ด๋
sudo apt-mark unhold kubelet kubectl && \
sudo apt-get update && sudo apt-get install -y kubelet='1.31.0-1.1' kubectl='1.31.0-1.1' && \
sudo apt-mark hold kubelet kubectl
Bash
๋ณต์ฌ
6.
kubelet ์ฌ์์
sudo systemctl daemon-reload
sudo systemctl restart kubelet
Bash
๋ณต์ฌ
7.
controlplane์ผ๋ก ๋์์ ํ์ธ
controlplane ~ โ kubectl get nodes
NAME STATUS ROLES AGE VERSION
controlplane Ready control-plane 76m v1.31.0
node01 Ready,SchedulingDisabled <none> 76m v1.31.0
Bash
๋ณต์ฌ
Documents
Q13
Remove the restriction and mark the worker node as schedulable again.
ํ์ด
controlplane ~ โ kubectl get nodes
NAME STATUS ROLES AGE VERSION
controlplane Ready control-plane 76m v1.31.0
node01 Ready <none> 75m v1.31.0
Bash
๋ณต์ฌ