Skip to main content

Pregunta 18 - Corregir Kubelet

Question 18 | Fix Kubelet

Use context: kubectl config use-context k8s-c3-CCC

There seems to be an issue with the kubelet not running on cluster3-node1. Fix it and confirm that cluster has node cluster3-node1 available in Ready state afterwards. You should be able to schedule a Pod on cluster3-node1 afterwards.

Write the reason of the issue into /opt/course/18/reason.txt.

Answer:

The procedure on tasks like these should be to check if the kubelet is running, if not start it, then check its logs and correct errors if there are some.

Always helpful to check if other clusters already have some of the components defined and running, so you can copy and use existing config files. Though in this case it might not need to be necessary.



kubectl config use-context k8s-c3-CCC
# Vamos a buscar cuál node está con problema
k get node
NAME STATUS ROLES AGE VERSION
cluster3-controlplane1 Ready control-plane 14d v1.29.0
cluster3-node1 NotReady <none> 14d v1.29.0

## Vamos a entrar en el node y verificar el kubelet
ssh cluster3-node1
root@cluster3-node1:~# ps aux | grep kubelet
root 29294 0.0 0.2 14856 1016 pts/0 S+ 11:30 0:00 grep --color=auto kubelet

# No está ejecutándose. Podemos verificar el status del servicio
root@cluster3-node1:~# service kubelet status
# O systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/kubelet.service.d

└─10-kubeadm.conf
Active: inactive (dead) (Result: exit-code) since Thu 2024-01-04 13:12:54 UTC; 1h 23min ago
Docs: https://kubernetes.io/docs/
Process: 27577 ExecStart=/usr/local/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=>
Main PID: 27577 (code=exited, status=203/EXEC)

Jan 04 13:12:52 cluster3-node1 systemd[1]: kubelet.service: Main process exited, code=exited, status=203/EXEC
Jan 04 13:12:52 cluster3-node1 systemd[1]: kubelet.service: Failed with result 'exit-code'.
Jan 04 13:12:54 cluster3-node1 systemd[1]: Stopped kubelet: The Kubernetes Node Agent.

# Está inactivo. Vamos a intentar iniciar nuevamente
service kubelet start
# o systemctl start kuberlet
root@cluster3-node1:~# service kubelet status
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: activating (auto-restart) (Result: exit-code) since Thu 2024-01-04 14:37:02 UTC; 6s ago
Docs: https://kubernetes.io/docs/
Process: 27935 ExecStart=/usr/local/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=>
Main PID: 27935 (code=exited, status=203/EXEC)

Jan 04 14:37:02 cluster3-node1 systemd[1]: kubelet.service: Main process exited, code=exited, status=203/EXEC
Jan 04 14:37:02 cluster3-node1 systemd[1]: kubelet.service: Failed with result 'exit-code'.

# Analizando arriba el problema tenemos
#Process: 27935 ExecStart=/usr/local/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS #$KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=>
#Main PID: 27935 (code=exited, status=203/EXEC)

# La llamada para kubelet no está subiendo. Si fuéramos a ejecutar el kubelet necesitamos hacer esto
root@cluster3-node1:~# /usr/local/bin/kubelet
-bash: /usr/local/bin/kubelet: No such file or directory
# Esta ruta no apunta para el kubelet

root@cluster3-node1:~# whereis kubelet
kubelet: /usr/bin/kubelet

# es necesario corregir la ruta del binario en
vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf

# Ahora haga el start nuevamente, pero es necesario hacer el reload antes
systemctl daemon-reload
service kubelet restart
service kubelet status # Ahora deberá estar running

# volviendo al terminal estándar

k get node
NAME STATUS ROLES AGE VERSION
cluster3-controlplane1 Ready control-plane 14d v1.29.0
cluster3-node1 Ready <none> 14d v1.29.0

# El motivo es que la ruta para el kubelet está errada. Pero vamos a escribir esto en el archivo en inglés.
echo "wrong path to kubelet binary in service config" > /opt/course/18/reason.txt