Ejercicios Docker, Kubernetes, OpenShift
Ejercicios Docker, Kubernetes, OpenShift
Ejercicios Docker, Kubernetes, OpenShift
OpenShift
1. Intro con Docker labs 3
8. Observa que este run no saca ningún texto de salida, el hello-world sí lo hacía.
9. Prueba a lanzar docker image ls y observa el listado de imágenes disponibles
1. Descargar la VM de Windows
https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
a. Antes de arrancar subirle la memoria a 4GB y ponerle un par de cores
b. Al ejecutarla instalar Chrome y desanclar Internet Edge de la barra de tareas
2. Instalar Docker
a. Puede ser necesario habilitar virtualización en la bios del ordenador y en las
opciones del visor de la VM
b. Después de instalar Docker se debe instalar WSL2 Linux Kernel y requiere otro
reinicio. Si nos sale el segundo pantallazo antes de reiniciar hay que seguir el
link y pulsar en el primer link, descargar un exe e instalarlo:
3. Al arrancar Docker Desktop deberíamos ver un icono en la parte inferior derecha de una
ballena con contenedores encima
Empezamos bajando archivos que van a contener varios recursos necesarios para el ejercicio
Ahora lo correcto es analizar con detalle cada carpeta buscando archivos relevantes para el
curso (dockerfiles, compose.yaml,...), encontramos un dockerfile en la carpeta vote
https://docs.docker.com/compose/gettingstarted/
Seguramente al usar una maquina windows os pase este problema con las extensiones ocultas
Finalmente debería ejecutar correctamente (cuidado con tener el puerto 5000 abierto de
ejercicios anteriores, si arrancasteis con swarm, el swarm os reiniciara los contenedores al
apagarlos)
FROM tomcat
MAINTAINER raullapeira
RUN apt-get update && apt-get -y upgrade
WORKDIR /usr/local/tomcat
COPY HelloWorld.war /usr/local/tomcat/webapps/HelloWorld.war
EXPOSE 8080
Creamos la imagen, nos debería descargar primero las imágenes de las capas que forman la
imagen de Tomcat y después construirla
https://kubernetes.io/es/docs/tasks/tools/install-minikube/
Pasos
Vamos a usar esta guía paso a paso para ver el proceso completo
https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/cluster-interactive/
Espera a que los comandos devuelvan el prompt y comprueba el resultado de los componentes
que vamos arrancando
Google Cloud Registry
El google cloud registry tiene un dominio de alias en gcr.io de manera que
gcr.io/google-samples/kubernetes-bootcamp
https://kubernetes.io/docs/tutorials/stateless-application/guestbook/
Nos pedirá una cuenta de registro pero no debería solicitar tarjeta de crédito.
https://github.com/jboss-openshift/openshift-quickstarts/tree/master/tomcat-websocket-chat
http://jws-app-raullapeira-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com/websocket-chat/
Como hemos desplegado un contenedor de una imagen que solo tiene tomcat, tendría sentido
conectar nuestro contenedor de Tomcat con otro de PostgreSQL o MySQL
https://github.com/snowdrop/rest-http-example/tree/master/.openshiftio
Caused by:
java.lang.NoClassDefFound
Error:
javax/xml/bind/JAXBExcept
ion
¿Por qué se produce este fallo? ¿es un problema de la imagen? ¿de openshift? ¿de las
librerías de la aplicación?, plantee sus dudas en clase al formador o a los compañeros.
Compose does not use swarm mode to deploy services to multiple nodes
in a swarm. All containers will be scheduled on the current node.
Building web
Step 1/10 : FROM python:3.7-alpine
3.7-alpine: Pulling from library/python
df20fa9351a1: Already exists
36b3adc4ff6f: Pull complete
4db9de03f499: Pull complete
cd38a04a61f4: Pull complete
9a3838385f13: Pull complete
Digest:
sha256:9fbee97d521b846689f4dbf0d5f2770c734d4a09e6d0a0991efc916c58970e
99
Status: Downloaded newer image for python:3.7-alpine
---> 295b051ee125
Step 2/10 : WORKDIR /code
---> Running in a66a2e0ed02b
Removing intermediate container a66a2e0ed02b
---> bc0abed17805
Step 3/10 : ENV FLASK_APP=app.py
---> Running in 46e2b2e11755
Removing intermediate container 46e2b2e11755
---> f5664bf71ee1
Step 4/10 : ENV FLASK_RUN_HOST=0.0.0.0
---> Running in 8bef14c059ff
Removing intermediate container 8bef14c059ff
---> 29451d2b01f4
Step 5/10 : RUN apk add --no-cache gcc musl-dev linux-headers
---> Running in 675cda512091
fetch
http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.g
z
fetch
http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.
tar.gz
(1/13) Installing libgcc (9.3.0-r2)
(2/13) Installing libstdc++ (9.3.0-r2)
(3/13) Installing binutils (2.34-r1)
(4/13) Installing gmp (6.2.0-r0)
(5/13) Installing isl (0.18-r0)
(6/13) Installing libgomp (9.3.0-r2)
(7/13) Installing libatomic (9.3.0-r2)
(8/13) Installing libgphobos (9.3.0-r2)
(9/13) Installing mpfr4 (4.0.2-r4)
(10/13) Installing mpc1 (1.1.0-r1)
(11/13) Installing gcc (9.3.0-r2)
(12/13) Installing linux-headers (5.4.5-r1)
(13/13) Installing musl-dev (1.1.24-r9)
Executing busybox-1.31.1-r16.trigger
OK: 153 MiB in 48 packages
Removing intermediate container 675cda512091
---> e2ab9084a38f
Step 6/10 : COPY requirements.txt requirements.txt
---> 19c37364e179
Step 7/10 : RUN pip install -r requirements.txt
---> Running in 7c6fab002a1b
Collecting flask
Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting redis
Downloading redis-3.5.3-py2.py3-none-any.whl (72 kB)
Collecting Jinja2>=2.10.1
Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
Collecting Werkzeug>=0.15
Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
Collecting click>=5.1
Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting itsdangerous>=0.24
Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting MarkupSafe>=0.23
Downloading MarkupSafe-1.1.1.tar.gz (19 kB)
Building wheels for collected packages: MarkupSafe
Building wheel for MarkupSafe (setup.py): started
Building wheel for MarkupSafe (setup.py): finished with status
'done'
Created wheel for MarkupSafe:
filename=MarkupSafe-1.1.1-cp37-cp37m-linux_x86_64.whl size=16913
sha256=cf4819e501d00b066582ae405b9f28bd720b4031780639dddebf73aa84c120
e0
Stored in directory:
/root/.cache/pip/wheels/b9/d9/ae/63bf9056b0a22b13ade9f6b9e08187c1bb71
c47ef21a8c9924
Successfully built MarkupSafe
Installing collected packages: MarkupSafe, Jinja2, Werkzeug, click,
itsdangerous, flask, redis
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1
click-7.1.2 flask-1.1.2 itsdangerous-1.1.0 redis-3.5.3
Removing intermediate container 7c6fab002a1b
---> ef7b5b8ef2ae
Step 8/10 : EXPOSE 5000
---> Running in 23a028a72780
Removing intermediate container 23a028a72780
---> 202a371ebc4e
Step 9/10 : COPY . .
---> fb5721e8d1e1
Step 10/10 : CMD ["flask", "run"]
---> Running in 638ff8022c7c
Removing intermediate container 638ff8022c7c
---> 368847a7f67d
ERROR: for web Cannot start service web: driver failed programming
external connectivity on endpoint composetest_web_1
(8002e568dfdb15fafb37eb91737576c29d4dc09fca4850e642830ccbd1c8f9a7):
Error starting userland proxy: listen tcp 0.0.0.0:5000: bind: address
already in use
ERROR: Encountered errors while bringing up the project.
PS C:\Users\User\composetest> docker-compose up
Creating composetest_redis_1 ... done
Creating composetest_web_1 ... done
Attaching to composetest_redis_1, composetest_web_1
redis_1 | 1:C 24 Sep 2020 09:38:49.713 # oO0OoO0OoO0Oo Redis is
starting oO0OoO0OoO0Oo
redis_1 | 1:C 24 Sep 2020 09:38:49.713 # Redis version=6.0.8,
bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 24 Sep 2020 09:38:49.713 # Warning: no config file
specified, using the default config. In order to specify a config
file use redis-server /path/to/redis.conf
redis_1 | 1:M 24 Sep 2020 09:38:49.716 * Running mode=standalone,
port=6379.
redis_1 | 1:M 24 Sep 2020 09:38:49.716 # WARNING: The TCP backlog
setting of 511 cannot be enforced because
/proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 24 Sep 2020 09:38:49.716 # Server initialized
redis_1 | 1:M 24 Sep 2020 09:38:49.716 # WARNING overcommit_memory
is set to 0! Background save may fail under low memory condition. To
fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and
then reboot or run the command 'sysctl vm.overcommit_memory=1' for
this to take effect.
redis_1 | 1:M 24 Sep 2020 09:38:49.716 # WARNING you have
Transparent Huge Pages (THP) support enabled in your kernel. This
will create latency and memory usage issues with Redis. To fix this
issue run the command 'echo madvise >
/sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to
your /etc/rc.local in order to retain the setting after a reboot.
Redis must be restarted after THP is disabled (set to 'madvise' or
'never').
redis_1 | 1:M 24 Sep 2020 09:38:49.716 * Ready to accept connections
web_1 | * Serving Flask app "app.py"
web_1 | * Environment: production
web_1 | WARNING: This is a development server. Do not use it in
a production deployment.
web_1 | Use a production WSGI server instead.
web_1 | * Debug mode: off
web_1 | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)