Skip to content

Commit 5f99c27

Browse files
committed
Ejercicios orquestación dia 1
1 parent 36bec7e commit 5f99c27

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Poner en marcha minikube
2+
minikube start
3+
# Si usas kind
4+
# kind create cluster
5+
6+
# Listar los nodos
7+
kubectl get nodes
8+
kubectl get nodes -o wide # Muestra más info
9+
10+
# Ejecutar un contenedor de un solo uso (hello-world)
11+
kubectl run hello -i --image hello-world --restart=Never --rm
12+
13+
# Los contenedores realmente son pods
14+
kubectl run hello -i --image hello-world --restart=Never # Como antes pero sin --rm
15+
kubectl get po # o get pod, o get pods
16+
17+
# NAME READY STATUS RESTARTS AGE
18+
# hello 0/1 Completed 0 7s
19+
20+
# Mostrar datos adicionales (p. ej. la IP interna del pod)
21+
kubectl get po -o wide # Muestra datos adicionales
22+
23+
# Eliminar el pod
24+
kubectl delete po hello
25+
26+
# Un pod por defecto intenta reiniciar el contenedor si ese termina
27+
kubectl run hello --image hello-world
28+
# Espera unos segundos... La columna RESTARTS será > 0
29+
kubectl get po
30+
31+
# NAME READY STATUS RESTARTS AGE
32+
# hello 0/1 Completed 2 23s
33+
34+
kubectl delete po hello # Limpieza :)
35+
36+
# Pull de la imagen de crash (eiximenis/crash)
37+
# Nota: Puedes construirla tu mismo a partir del Dockerfile en el directorio crash
38+
# Si lo haces debes construirla y subirla a un registro público. Usa el nombre de tu
39+
# imagen en lugar de 'eiximenis/crash'
40+
docker pull eiximenis/crash
41+
42+
# Nunca reiniciar
43+
kubectl run crash1 --image eiximenis/crash --restart=Never
44+
# Pod queda en estado error:
45+
kubectl get po
46+
47+
# NAME READY STATUS RESTARTS AGE
48+
# crash1 0/1 Error 0 11s
49+
50+
# Pod con reinicio
51+
kubectl run crash2 --image eiximenis/crash
52+
# Pod se va reiniciando (RESTARTS > 0)
53+
kubectl get po
54+
55+
# NAME READY STATUS RESTARTS AGE
56+
# crash1 0/1 Error 0 87s
57+
# crash2 0/1 CrashLoopBackOff 2 31s
58+
59+
kubectl delete po crash{1..2} # Limpieza
60+
61+
# Ejecutar un nginx
62+
kubectl run nginx --image nginx
63+
64+
# Ejecutar una API hello world y exponer puerto 80
65+
kubectl run helloworld --image eiximenis/go-hello-world --port=80
66+
# Usar port-forward para vincular el puerto 8080 local al 80 del pod
67+
kubectl port-forward helloworld 8080:80
68+
kubectl port-forward helloworld 8080:80 >/dev/null &
69+
curl http://localhost:8080
70+
# Hello, world! You have called me 1 times.
71+
72+
kill $(ps -ef | grep kubectl | awk {'print $2'}) # Matamos kubectl
73+
kubectl delete pod helloworld # Limpieza :)
74+
75+
# Ejecutar nginx con variables de entorno
76+
kubectl run nginx --image nginx --env foo=bar
77+
# Verificar variables
78+
kubectl exec -it nginx -- /bin/sh -c 'env' | grep foo
79+
kubectl delete pod nginx # Limpieza :)
80+
81+
# Ejectuar PostgreSQL
82+
kubectl run pgsql --image postgres --env POSTGRES_PASSWORD=123abc!
83+
# Ejecutar Adminer
84+
kubectl run adminer --image adminer --port=8080
85+
# Usar port-forward para acceder
86+
kubectl port-forward adminer 8080:8080
87+
# En este punto abrir navegador a localhost:8080 y entrar en la BBDD.
88+
# Matar kubectl al terminar
89+
90+
# Ver los logs
91+
kubectl logs pgsql
92+
# Usar describe
93+
kubectl describe pod pgsql
94+
95+
kubectl delete po pgsql # Limpieza :)
96+
kubectl delete pod adminer # Limpieza :)
97+
98+
99+
100+
101+
102+

0 commit comments

Comments
 (0)