Este artigo foi atualizado em 2022-03-04, o conteúdo pode estar desatualizado.
Olá Pessoal, tudo bem?
Neste tutorial vou-lhes explicar como fazer deploy de um cluster simples do OpenShift para provas através da aplicação CodeReady Containers.
O OpenShift é a solução da Red Hat para a orquestação de conteiners basado em Kubernetes. ¿Te animas a provar a última versão do OpenShift sem ter que instalar um grupo de masters e workers?
Ao momento desta publicação, teremos instalada a versão 4.4.8 do OpenShift.
ATUALIZAÇÃO 23/07/2020: Já está liberada a versâo 4.5.1 do OpenShift, pelo que se segues a realizar os mesmos passos cá descritos, vais poder provar a última versão
Requisitos Mínimos de Hardware
Para poder executar corretamente o OpenShift, vamos precisar dos requisitos mínimos de Hardware a seguir:
4 CPUs virtuales (vCPUs)
8 GB de memória RAM.
35 GB de espaço no disco duro.
CodeReady Containers pode ser executado quanto no Linux, Windows ou MacOS. Porém, o provei no Fedora 32 e no CentOS 7. CodeReady Contains vem empacotado numa máquina virtual Red Hat Enterprise Linux que usar os hipervisores nativos do Linux (libvirt/KVM), Windows 10 (Hyper-V) e MacOS (HyperKit).
Passo 1: Registar-nos no website Developers de Red Hat
Para poder baixar o executable de CodeReady Containers, vamos precisar registar-nos no seguinte link: Red Hat Developers aliás de obter a nossa chave Secret Pull.
Passo 2: Instalar dependências necessárias
CodeReady Containers precisa os pacotes libvirt e NetworkManager, os quais devem ser instalados.
$ crc --help
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.
Passo 4: Configurar a máquina virtual de CodeReady Containers
Executamos o seguinte comando para configurar a máquina host:
1
$ crc setup
O instalador vai comprobar os requisitos do sistema antes de fazer o deploy da 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
Uma vez a que a comprobação finalizar, iniciamos o cluster como o seguinte comando:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ crc start
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]
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
Veremos as as credenciais de acesso nas últimas 6 linhas:
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 o acesso ao cluster, a configurar as variáveis de ambiente:
Atualizamos a shell para que podamos executar os comandos do OpenShift:
1
2
3
4
5
6
7
8
9
bash
$ vim ~/.bashrc
exportPATH="~/.crc/bin:$PATH"eval$(crc oc-env)zsh
$ vim ~/.zshrc
exportPATH="~/.crc/bin:$PATH"eval$(crc oc-env)
E depois source
1
2
3
4
5
bash
$ source ~/.bashrc
zsh
$ source ~/.zshrc
Iniciamos sessão como admin, com o seguinte comando:
1
2
3
4
5
6
7
8
9
10
$ oc login -u kubeadmin -p fq66o-KsVBU-cnKBU-xLpqd https://api.crc.testing:6443
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 a configuração do cluster:
1
2
3
4
$ oc cluster-info
Kubernetes master is running at https://api.crc.testing:6443
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
1
2
3
$ oc get nodes
NAME STATUS ROLES AGE VERSION
crc-rtgqw-master-0 Ready master,worker 19d v1.17.1+3f6f40d
Pode se acessar ao cluster localmente pela consola ou pela consola web:
1
2
3
4
5
6
7
8
9
10
S oc login -u developer -p developer https://api.crc.testing:6443
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>
Acessar como administrador:
1
2
3
4
5
6
7
8
9
10
$ oc login -u kubeadmin -p fq66o-KsVBU-cnKBU-xLpqd https://api.crc.testing:6443
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 a consola web desde o seu navegador padrão:
1
$ crc console
LoginEcrã Iniciar SessãoEcrã Principal
Si queremos saber la dirección IP del cluster:
1
$ crc ip
Passo 6: Parar o cluster el cluster do OpenShift
Para parar o cluster, executamos o seguinte comando:
1
2
3
$ crc stop
Stopping the OpenShift cluster, this may take a few minutes...
Stopped the OpenShift cluster
Pode ser iniciado novamente simplesmente a executar:
1
$ crc start
Passo 7: Apagar o cluster do OpenShift
Se queremos apagar o cluster do disco duro:
1
$ crc delete
Espero que tinham gostado deste tutorial, até a próxima!