Pular para o conteúdo principal

Lab 10.4 - Helmfile e Multiambientes

Objetivos do Lab​

Ao final deste lab, você será capaz de:

  • Instalar o Helmfile.
  • Compreender a estrutura de um helmfile.yaml.
  • Gerenciar múltiplos ambientes (dev, staging, prod).
  • Fazer o deploy de aplicações com o Helmfile.

Duração Estimada​

45-60 minutos

Pré-requisitos​

  • Helm instalado e configurado.
  • Cluster Kubernetes local funcional.
  • Conhecimentos sobre Helm (Labs anteriores).

Parte 1: Instalação do Helmfile​

Etapa 1.1: Instalar o Helmfile​

No Linux/Mac:

wget https://github.com/helmfile/helmfile/releases/download/v0.153.1/helmfile_0.153.1_linux_amd64.tar.gz
tar -xzf helmfile_0.153.1_linux_amd64.tar.gz
sudo mv helmfile /usr/local/bin/

No Windows (com Chocolatey):

choco install helmfile

Verifique:

helmfile version

Parte 2: Criação de um helmfile.yaml​

Etapa 2.1: Criar um helmfile.yaml Simples​

Crie helmfile.yaml:

repositories:
- name: bitnami
url: https://charts.bitnami.com/bitnami

releases:
- name: nginx
namespace: default
chart: bitnami/nginx
values:
- replicaCount: 2
service:
type: ClusterIP

Etapa 2.2: Fazer o Deploy com o Helmfile​

helmfile sync

Parte 3: Multiambientes​

Etapa 3.1: Criar a Estrutura​

Crie pastas para os ambientes:

mkdir -p environments/{dev,staging,prod}

Etapa 3.2: Criar helmfile.yaml com Ambientes​

Crie helmfile.yaml:

environments:
default:
values:
- environments/dev/values.yaml
staging:
values:
- environments/staging/values.yaml
prod:
values:
- environments/prod/values.yaml

releases:
- name: my-app
namespace: {{ .Values.namespace }}
chart: bitnami/nginx
values:
- replicaCount: {{ .Values.replicaCount }}

Etapa 3.3: Criar os Arquivos de Valores​

Crie environments/dev/values.yaml:

namespace: dev
replicaCount: 1

Crie environments/staging/values.yaml:

namespace: staging
replicaCount: 2

Crie environments/prod/values.yaml:

namespace: prod
replicaCount: 3

Etapa 3.4: Fazer o Deploy para um Ambiente​

# Desenvolvimento
helmfile -e dev sync

# Staging
helmfile -e staging sync

# Produção
helmfile -e prod sync

Parte 4: Gerenciamento com Helmfile​

Etapa 4.1: Listar as Releases​

helmfile list

Etapa 4.2: Remover​

helmfile destroy

Resumo do Lab​

Neste lab, você utilizou o Helmfile para gerenciar deploys multiambientes. Você aprendeu a estruturar suas configurações e a fazer deploy em diferentes ambientes.


Próximos Passos​

Este módulo sobre Helm está agora completo. Você pode avançar para o Módulo 11 sobre Monitoring e Observabilidade.

Módulo 11: Monitoring e Observabilidade


Lab criado em: Dezembro 2024