Este artículo se actualizó por última vez el 2021-03-20, el contenido puede estar desactualizado.
¡Hola a todos!
En este tutorial les voy a explicar como desplegar un cluster sencillo de OpenShift para pruebas a través de la aplicación CodeReady Containers.
OpenShift es la solución de Red Hat para la orquestación de contenedores basado en Kubernetes. ¿Te animas a probar la última versión de OpenShift sin tener que instalar un set de masters y workers?
Al momento de esta publicación, tendremos instalada la version 4.7.0 de OpenShift.
Requisitos Minimos de Hardware
Para poder correr correctamente OpenShift, necesitaremos de estos requisitos mínimos de Hardware:
4 CPUs virtuales (vCPUs)
8 GB memoria RAM.
35 GB de espacio en disco duro.
CodeReady Containers se puede ejecutar tanto en Linux, Windows o MacOS. Sin embargo, para este tutorial lo he probado en Fedora 32 y CentOS 7. CodeReady Containers viene empaquetado como una máquina virtual Red Hat Enterprise Linux que utiliza los hipervisores nativos de Linux (libvirt/KVM), Windows 10 (Hyper-V) y MacOS (HyperKit).
Paso 1: Registrarnos en la página Developers de Red Hat
Para poder descargar el ejecutable de CodeReady Containers, vamos a necesitar registrarnos en el siguiente enlace: Red Hat Developers y además obtener nuestra clave Secret Pull.
Paso 2: Instalamos dependencias necesarias
CodeReady Containers necesita los paquetes libvirt y NetworkManager, los cuales deben ser instalados.
CodeReady Containers is a tool that manages a local OpenShift 4.x cluster optimized for testing and development purposes
Usage:
crc [flags] crc [command]Available Commands:
cleanup Undo config changes
config Modify crc configuration
console Open the OpenShift Web Console in the default browser
delete Delete the OpenShift cluster
help Help about any command ip Get IP address of the running OpenShift cluster
oc-env Add the 'oc' binary to PATH
podman-env Setup podman environment
setup Set up prerequisites for the OpenShift cluster
start Start the OpenShift cluster
status Display status of the OpenShift cluster
stop Stop the OpenShift cluster
version Print version information
Flags:
-f, --force Forcefully perform an action
-h, --help helpfor crc
--log-level string log level (e.g. "debug | info | warn | error")(default "info")Use "crc [command] --help"for more information about a command.
Paso 4: Configuramos la máquina virtual de CodeReady Containers
Ejecutamos el siguiente comando para configurar la máquina anfitriona:
1
crc setup
El instalador va a comprobar los requerimientos del sistema antes de desplegar la máquina virtual.
INFO Checking if oc binary is cached
INFO Caching oc binary
INFO Checking if podman remote binary is cached
INFO Checking if goodhosts binary is cached
INFO Caching goodhosts binary
INFO Checking if CRC bundle is cached in '$HOME/.crc'INFO Unpacking bundle from the CRC binary
INFO Checking if running as non-root
INFO Checking if Virtualization is enabled
INFO Checking if KVM is enabled
INFO Checking if libvirt is installed
INFO Checking if user is part of libvirt group
INFO Checking if libvirt is enabled
INFO Checking if libvirt daemon is running
INFO Checking if a supported libvirt version is installed
INFO Checking if crc-driver-libvirt is installed
INFO Installing crc-driver-libvirt
INFO Checking for obsolete crc-driver-libvirt
INFO Checking if libvirt 'crc' network is available
INFO Checking if libvirt 'crc' network is active
INFO Checking if NetworkManager is installed
INFO Checking if NetworkManager service is running
INFO Checking if /etc/NetworkManager/conf.d/crc-nm-dnsmasq.conf exists
INFO Checking if /etc/NetworkManager/dnsmasq.d/crc.conf exists
Setup is complete, you can now run 'crc start' to start the OpenShift cluster
Una vez que la comprobación se haya realizado, iniciamos el cluster con el siguiente comando:
1
crc start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
INFO Checking if oc binary is cached
INFO Checking if podman remote binary is cached
INFO Checking if goodhosts binary is cached
INFO Checking if running as non-root
INFO Checking if Virtualization is enabled
INFO Checking if KVM is enabled
INFO Checking if libvirt is installed
INFO Checking if user is part of libvirt group
INFO Checking if libvirt daemon is running
INFO Checking if a supported libvirt version is installed
INFO Checking if crc-driver-libvirt is installed
INFO Checking if libvirt 'crc' network is available
INFO Checking if libvirt 'crc' network is active
INFO Checking if NetworkManager is installed
INFO Checking if NetworkManager service is running
INFO Checking if /etc/NetworkManager/conf.d/crc-nm-dnsmasq.conf exists
INFO Checking if /etc/NetworkManager/dnsmasq.d/crc.conf exists
? Image pull secret [? for help]
Observe que va a necesitar la clave Pull Secret para continuar con la instalación, la cual puede copiar o descargar desde el siguiente enlace Install on Laptop: Red Hat CodeReady Containers
Pegue la clave Pull Secret en la terminal, y la instalación continuará (este proceso demorará algunos minutos dependiendo de su hardware):
INFO Extracting bundle: crc_libvirt_4.4.8.crcbundle ...
INFO Checking size of the disk image /home/enmanuelmoreira/.crc/cache/crc_libvirt_4.4.8/crc.qcow2 ...
INFO Creating CodeReady Containers VM for OpenShift 4.4.8...
INFO CodeReady Containers VM is running
INFO Verifying validity of the cluster certificates ...
INFO Check internal and public DNS query ...
INFO Check DNS query from host ...
INFO Generating new SSH key
INFO Copying kubeconfig file to instance dir ...
INFO Starting OpenShift kubelet service
INFO Configuring cluster for first start
INFO Adding user's pull secret ...
INFO Updating cluster ID ...
INFO Starting OpenShift cluster ... [waiting 3m]
INFO
INFO To access the cluster, first set up your environment by following 'crc oc-env' instructions
INFO Then you can access it by running 'oc login -u developer -p developer https://api.crc.testing:6443'
INFO To login as an admin, run 'oc login -u kubeadmin -p fq66o-KsVBU-cnKBU-xLpqd https://api.crc.testing:6443'
INFO
INFO You can now run 'crc console' and use these credentials to access the OpenShift web console
Started the OpenShift cluster
WARN The cluster might report a degraded or error state. This is expected since several operators have been disabled to lower the resource usage. For more information, please consult the documentation
Las credenciales de acceso las veremos en las últimas 6 lineas:
1
2
3
INFO Then you can access it by running 'oc login -u developer -p developer https://api.crc.testing:6443'INFO To login as an admin, run 'oc login -u kubeadmin -p fq66o-KsVBU-cnKBU-xLpqd https://api.crc.testing:6443'INFO You can now run 'crc console' and use these credentials to access the OpenShift web console
Habilitamos el acceso al cluster, configurando las variables de entorno:
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be intercepted by others.
Use insecure connections? (y/n): y
Login successful.
You have access to 57 projects, the list has been suppressed. You can list all projects with 'oc projects'Using project "default".
Confirmamos la configuración del cluster:
1
oc cluster-info
1
2
3
Kubernetes master is running at https://api.crc.testing:6443
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
1
oc get nodes
1
2
NAME STATUS ROLES AGE VERSION
crc-rtgqw-master-0 Ready master,worker 19d v1.17.1+3f6f40d
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be intercepted by others.
Use insecure connections? (y/n): y
Login successful.
You don't have any projects. You can try to create a new project, by running
oc new-project <projectname>
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be intercepted by others.
Use insecure connections? (y/n): y
Login successful.
You have access to 57 projects, the list has been suppressed. You can list all projects with 'oc projects'Using project "default".
Para abrir la consola web desde su navegador predeterminado:
1
crc console
Si queremos saber la dirección IP del cluster:
1
crc ip
Paso 6: Deteniendo el cluster de OpenShift
Para detener el cluster, ejecutamos el siguiente comando:
1
crc stop
1
2
Stopping the OpenShift cluster, this may take a few minutes...
Stopped the OpenShift cluster
Se puede iniciar nuevamente el cluster simplemente ejecutando:
1
crc start
Paso 7: Eliminando el cluster de OpenShift
Si queremos borrar el cluster desplegado y ahorrarnos ese espacio en disco duro:
1
crc delete
Espero les haya gustado este tutorial, ¡hasta la próxima!
Apoya este Proyecto!!!
Si te pareció útil este artículo y el proyecto en general, considera brindarme un café :)