반응형
https://killer.sh 모의고사 오답노트입니다.
Question 20 | Update Kubernetes Version and join cluster
Your coworker said node cluster3-worker2
is running an older Kubernetes version and is not even part of the cluster. Update Kubernetes on that node to the exact version that's running on cluster3-master1
. Then add this node to the cluster. Use kubeadm for this.
너의 동료가 말하길 cluster3-worker2
가 구버전 쿠버네티스 버전을 쓰고, 클러스터의 일부도 아니라고 한다.
- 마스터 버전으로 업그레이드하고
- 이 노드를 클러스터에 입적시켜라.
- kubeadm 를 이용해라.
키워드
- kubeadm, kubelet, kubectl 을 업그레이드
- kubelet 이 없다 == 노드가 안생김 == kubeadm join 연산을 마스터에서 복붙해와서 붙여야한다.
1. Upgrade Kubernetes to cluster3-master1 version
Search in the docs for kubeadm upgrade: https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade
- 마스터 버전 확인
➜ k get node
NAME STATUS ROLES AGE VERSION
cluster3-master1 Ready control-plane 23d v1.24.1
cluster3-worker1 NotReady <none> 23d v1.24.1
- 마스터버전이 1.24.1 으로 확인됐고, worker2는 클러스터의 일부가 아닌것으로 보인다.
- worker2 상태 확인 (kubeadm, kubectl , kubelet 버전 체크)
➜ ssh cluster3-worker2
➜ root@cluster3-worker2:~# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.1", GitCommit:"3ddd0f45aa91e2f30c70734b175631bec5b5825a", GitTreeState:"clean", BuildDate:"2022-05-24T12:24:38Z", GoVersion:"go1.18.2", Compiler:"gc", Platform:"linux/amd64"}
➜ root@cluster3-worker2:~# kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:41:01Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
➜ root@cluster3-worker2:~# kubelet --version
Kubernetes v1.23.1
kubeadm 는 이미 우리가 원하는 버전인 것 같다. 그러므로 바로 노드를 업그레이드하자.
➜ root@cluster3-worker2:~# kubeadm upgrade node
couldn't create a Kubernetes client from file "/etc/kubernetes/kubelet.conf": failed to load admin kubeconfig: open /etc/kubernetes/kubelet.conf: no such file or directory
To see the stack trace of this error execute with --v=5 or higher
kubelet.conf 없다는디?
- 위의 command 는 흔한 노드 업그레이드 명령어인데, 이게 에러라는 소리는, 노드가 한번도 초기화도된 적이 없기에, 업데이트가 될 게 없다는 소리다.
kubeadm join
이후에 해당 명령어를 해줘야한다.
- kubelet, kubectl 은 먼저 업그레이드하자.
➜ root@cluster3-worker2:~# apt update
...
Fetched 5,775 kB in 2s (2,313 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
90 packages can be upgraded. Run 'apt list --upgradable' to see them.
➜ root@cluster3-worker2:~# apt show kubectl -a | grep 1.24
Version: 1.24.3-00
Version: 1.24.2-00
Version: 1.24.1-00
Version: 1.24.0-00
➜ root@cluster3-worker2:~# apt install kubectl=1.24.1-00 kubelet=1.24.1-00
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
kubectl kubelet
2 upgraded, 0 newly installed, 0 to remove and 69 not upgraded.
Need to get 28.6 MB of archives.
After this operation, 9,044 kB disk space will be freed.
Get:1 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 kubectl amd64 1.24.1-00 [9,318 kB]
Get:2 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 kubelet amd64 1.24.1-00 [19.3 MB]
Fetched 28.6 MB in 2s (15.5 MB/s)
(Reading database ... 112511 files and directories currently installed.)
Preparing to unpack .../kubectl_1.24.1-00_amd64.deb ...
Unpacking kubectl (1.24.1-00) over (1.23.1-00) ...
Preparing to unpack .../kubelet_1.24.1-00_amd64.deb ...
Unpacking kubelet (1.24.1-00) over (1.23.1-00) ...
Setting up kubectl (1.24.1-00) ...
Setting up kubelet (1.24.1-00) ...
➜ root@cluster3-worker2:~# kubelet --version
Kubernetes v1.24.1
- 우린 이제, kubeadm, kubelet, kubectl 이 최신인 것을 확인했다. kubelet 을 재시작하자.
➜ root@cluster3-worker2:~# systemctl restart kubelet
➜ root@cluster3-worker2:~# service kubelet status
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: activating (auto-restart) (Result: exit-code) since Thu 2022-08-04 11:31:25 UTC; 3s ago
Docs: https://kubernetes.io/docs/home/
Process: 35802 ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (>
Main PID: 35802 (code=exited, status=1/FAILURE)
2. Add cluster3-master2 to cluster
- master1 에 가서, tls 부트스트랩 토큰을 생성하자. 그리고 우리의 join 명령어를 호출하자.
➜ ssh cluster3-master1
➜ root@cluster3-master1:~# kubeadm token create --print-join-command
kubeadm join 192.168.100.31:6443 --token ez34if.qedae3br5r3mi7p2 --discovery-token-ca-cert-hash sha256:91f646b4fa8a0b69811ad1c412258c41fd76b7940d1a13802898728d8b5474c7
➜ root@cluster3-master1:~# kubeadm token list
TOKEN TTL EXPIRES ...
7aqkr7.q92y1za324u1g9fy <invalid> 2022-07-13T11:01:23Z ...
ez34if.qedae3br5r3mi7p2 23h 2022-08-05T11:32:02Z ...
tqddy8.r6yrlrgz6f0xwca6 <forever> <never> ...
- 우리 토큰 조인 명령어를 worker2 에 가서 실행하자.
➜ ssh cluster3-worker2
➜ root@cluster3-worker2:~# kubeadm join 192.168.100.31:6443 --token leqq1l.1hlg4rw8mu7brv73 --discovery-token-3c9cf14535ebfac8a23a91132b75436b36df2c087aa99c433f79d531
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
- 상태 확인
➜ root@cluster3-worker2:~# service kubelet status
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since Thu 2022-08-04 11:33:28 UTC; 50s ago
Docs: https://kubernetes.io/docs/home/
Main PID: 36138 (kubelet)
Tasks: 15 (limit: 462)
Memory: 54.2M
CGroup: /system.slice/kubelet.service
└─36138 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubele>
kubeadm join
이 안된다면,kubeadm restart
를 실행하라.
결론
➜ k get node
NAME STATUS ROLES AGE VERSION
cluster3-master1 Ready control-plane 23d v1.24.1
cluster3-worker1 Ready <none> 23d v1.24.1
cluster3-worker2 Ready <none> 2m24s v1.24.1
반응형
'쿠버네티스' 카테고리의 다른 글
cka 준비 팁 (0) | 2022.10.03 |
---|---|
[ cka 준비 오답노트 ] Fix Kubelet (0) | 2022.10.03 |