0

Crear Pod multi-pod .yaml

Armando Serrano
Armando Serrano

Requerimientos:

  1. Tener un cluster de kubernetes


Actividades:

  1. Crear un pod
  2. Desplegar un pod
  3. Listar pod
  4. Describir el pod
  5. Ver logs del pod
  6. Eliminar el pod

----------------------------------------------------------------------------------

[root@localhost ~]# touch multi_pod.yaml
[root@localhost ~]# vi multi_pod.yaml
### presiona la tecla "insert"  y copia lo sigueinte dentro del multi_pod.yaml ####

apiVersion: v1
kind: Pod
metadata:
  name: simple-pod
  namespace: default
  labels:
    app: simple-pod
spec:
  containers:
  - name: simple-pod
    image: busybox
    command:
      - sleep
      - "3600"
  - name:  nginx
    image: nginx


### presiona la tecla "ESC" y escribe ":wq"  ###


Desplegar un pod

[root@localhost ~]# kubectl apply -f multi_pod.yaml  -n default
pod/simple-pod created


Listar pod

[root@localhost ~]# kubectl get pods -n default
NAME         READY   STATUS    RESTARTS   AGE
simple-pod   2/2     Running   0          2m5s

### note que tiene 2 contenedores dentro de un mismo pod #### 

Describir el pod

 [root@localhost ~]# kubectl get pods -n default -o wide
NAME         READY   STATUS    RESTARTS   AGE     IP           NODE       NOMINATED NODE   READINESS GATES
simple-pod   2/2     Running   0          7m43s   172.17.0.3   minikube   <none>           <none>
[root@localhost ~]# clear
[root@localhost ~]# kubectl describe pod simple-pod -n default
Name:         simple-pod
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Sun, 13 Jun 2021 18:18:40 -0400
Labels:       app=simple-pod
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"app":"simple-pod"},"name":"simple-pod","namespace":"default"},"spe...
Status:       Running
IP:           172.17.0.3
IPs:
  IP:  172.17.0.3
Containers:
  simple-pod:
    Container ID:  docker://d48d0b2d5acb8ba3a565ac9620be58a2c218957a29935438c255a34df5e72d41
    Image:         busybox
    Image ID:      docker-pullable://busybox@sha256:930490f97e5b921535c153e0e7110d251134cc4b72bbb8133c6a5065cc68580d
    Port:          <none>
    Host Port:     <none>
    Command:
      sleep
      3600
    State:          Running
      Started:      Sun, 13 Jun 2021 18:18:48 -0400
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-zrhrj (ro)
  nginx:
    Container ID:   docker://7b44713f0b2fc70e5852c47c8f20af735f80d14eb2281c3499a1e821069b1caa
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sun, 13 Jun 2021 18:19:29 -0400
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-zrhrj (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-zrhrj:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-zrhrj
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  8m40s  default-scheduler  Successfully assigned default/simple-pod to minikube
  Normal  Pulling    8m39s  kubelet, minikube  Pulling image "busybox"
  Normal  Pulled     8m33s  kubelet, minikube  Successfully pulled image "busybox" in 6.303936256s
  Normal  Created    8m32s  kubelet, minikube  Created container simple-pod
  Normal  Started    8m32s  kubelet, minikube  Started container simple-pod
  Normal  Pulling    8m32s  kubelet, minikube  Pulling image "nginx"
  Normal  Pulled     7m59s  kubelet, minikube  Successfully pulled image "nginx" in 33.194862428s
  Normal  Created    7m52s  kubelet, minikube  Created container nginx
  Normal  Started    7m51s  kubelet, minikube  Started container nginx

### note la creacion de los dos contenedores "Started container simple-pod" , "Started container nginx" ########

Ver logs del pod

### veremos los logs decada uno de los contenedores contenidos dentro del pod ####

[root@localhost ~]# kubectl logs  simple-pod -c nginx -n default
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/06/13 22:19:29 [notice] 1#1: using the "epoll" event method
2021/06/13 22:19:29 [notice] 1#1: nginx/1.21.0
2021/06/13 22:19:29 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/06/13 22:19:29 [notice] 1#1: OS: Linux 3.10.0-1062.9.1.el7.x86_64
2021/06/13 22:19:29 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/06/13 22:19:29 [notice] 1#1: start worker processes
2021/06/13 22:19:29 [notice] 1#1: start worker process 32
2021/06/13 22:19:29 [notice] 1#1: start worker process 33

### con el "-c nombre_del_contenedor" le indicamos el contenedor que queremos ver sus logs ##

[root@localhost ~]# kubectl logs  simple-pod -c simple-pod  -n default


Eliminar el pod

[root@localhost ~]# kubectl delete pod simple-pod -n default
pod "simple-pod" deleted




0
0

Comentários (1)

0
Leonardo Demetrio

Leonardo Demetrio

13/06/2021 21:02

Eu não conheço busybox, mas cara muito bom!

Cara uma dica, tenta cola o código aqui do TXT e não do terminal !

Quanto ao cluster Kubernetes, cara acho legal da sua parte ensinar isso. Eu quebrava a cabeça para desenvolver um cluster de Kafka dentro do Kubernetes.



No sé sobre busybox, ¡pero muy buen amigo!

Amigo, un consejo, ¡intenta pegar aquí el código del TXT y no del terminal.

En cuanto al clúster de Kubernetes, hombre, creo que es amable de tu parte enseñar eso. Estrujé mi cerebro para desarrollar un clúster de Kafka dentro de Kubernetes.


Muito bom ! Very good !


Abraços