Skip to main content

Pregunta 9 - Detener Scheduler y Programación Manual

Question 9 | Kill Scheduler, Manual Scheduling

Use context: kubectl config use-context k8s-c2-AC

Ssh into the controlplane node with ssh cluster2-controlplane1. Temporarily stop the kube-scheduler, this means in a way that you can start it again afterwards.

Create a single Pod named manual-schedule of image httpd:2.4-alpine, confirm it's created but not scheduled on any node.

Now you're the scheduler and have all its power, manually schedule that Pod on node cluster2-controlplane1. Make sure it's running.

Start the kube-scheduler again and confirm it's running correctly by creating a second Pod named manual-schedule2 of image httpd:2.4-alpine and check if it's running on cluster2-node1.


kubectl config use-context k8s-c2-AC

k get node
NAME STATUS ROLES AGE VERSION
cluster2-controlplane1 Ready control-plane 26h v1.29.0
cluster2-node1 Ready <none> 26h v1.29.0

ssh cluster2-controlplane1

# Remover el manifiesto detendrá el scheduler. Vamos solo a moverlo a otra carpeta
root@cluster2-controlplane1:~# cd /etc/kubernetes/manifests/
root@cluster2-controlplane1:~# mv kube-scheduler.yaml ..

# Volviendo al terminal estándar vamos a crear el pod y esperar que no sea programado
k run manual-schedule --image=httpd:2.4-alpine
k get pod manual-schedule -o wide
NAME READY STATUS ... NODE NOMINATED NODE
manual-schedule 0/1 Pending ... <none> <none>

# Vamos a obtener este pod y colocarle un nodeName
k get pod manual-schedule -o yaml > /opt/course/9/manualpod.yaml

vim /opt/course/9/manualpod.yaml

Edita el archivo colocando la creación dirigida usando nodeName.

...
spec:
nodeName: cluster2-controlplane1 # agregar el nombre del nodo controlplane
containers:
- image: httpd:2.4-alpine
imagePullPolicy: IfNotPresent
name: manual-schedule
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-nxnc7
readOnly: true
dnsPolicy: ClusterFirst
...

Listo, ahora solo hay que lanzarlo usando replace

kubectl replace -f /opt/course/9/manualpod.yaml --force
# Y verifica si está funcionando
k get pod manual-schedule -o wide
NAME READY STATUS ... NODE
manual-schedule 1/1 Running ... cluster2-controlplane1

Vuelve al ssh y coloca el archivo en su lugar

ssh cluster2-controlplane1

# Remover el manifiesto detendrá el scheduler. Vamos solo a moverlo a otra carpeta
root@cluster2-controlplane1:~# cd /etc/kubernetes/
root@cluster2-controlplane1:~# mv kube-scheduler.yaml manifests/

# Ahora solo hay que lanzar otro pod. Vuelve al terminal normal
k run manual-schedule2 --image=httpd:2.4-alpine
k get pod -o wide | grep schedule
manual-schedule 1/1 Running ... cluster2-controlplane1
manual-schedule2 1/1 Running ... cluster2-node1

Vale la pena observar que solo pudimos programar el pod en cluster2-controlplane1 porque este no tenía un taint.