Pregunta 21 - Crear Static Pod y Service
Question 21 | Create a Static Pod and Service
Use context: kubectl config use-context k8s-c3-CCC
Create a Static Pod named my-static-pod in Namespace default on cluster3-controlplane1. It should be of image nginx:1.16-alpine and have resource requests for 10m CPU and 20Mi memory.
Then create a NodePort Service named static-pod-service which exposes that static Pod on port 80 and check if it has Endpoints and if it's reachable through the cluster3-controlplane1 internal IP address. You can connect to the internal node IPs from your main terminal.
ssh cluster3-controlplane1
root@cluster1-controlplane1:~# cd /etc/kubernetes/manifests/
root@cluster1-controlplane1:~# kubectl run my-static-pod --image=nginx:1.16-alpine -o yaml --dry-run=client > my-static-pod.yaml
vim my-static-pod.yaml
Vamos a editar este archivo... para adicionar el resource request
# my-static-pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: my-static-pod
name: my-static-pod
spec:
containers:
- image: nginx:1.16-alpine
name: my-static-pod
resources: # agregar
requests: # agregar
cpu: 10m # agregar
memory: 20Mi # agregar
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
Vamos a verificar si está ejecutándose.
k get pod -A | grep my-static
NAMESPACE NAME READY STATUS ... AGE
default my-static-pod-cluster3-controlplane1 1/1 Running ... 22s
# creando el service
k expose pod my-static-pod-cluster3-controlplane1 --name static-pod-service --type=NodePort --port 80
# verificando
k get svc,ep -l run=my-static-pod
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/static-pod-service NodePort 10.99.168.252 <none> 80:30352/TCP 30s
NAME ENDPOINTS AGE
endpoints/static-pod-service 10.32.0.4:80 30s
Looking good.