# Strimzi 2 **Tutorial Strinzi Kafka:** https://strimzi.io/docs/operators/0.30.0/quickstart . . . ## Iniciar Docker e minikube - **Iniciar o Docker desktop** com o kubernetes - **Iniciar minikube**: `minikube start` ![image](https://hackmd.io/_uploads/H1PEg3H0T.png) - Ver se o **status do minikube**, se ele iniciou: `minikube status` ![image](https://hackmd.io/_uploads/rk9Pl2BCp.png) . . . ## Instalando Strimzi - **Baixar strimzi** (no final da pagina): https://github.com/strimzi/strimzi-kafka-operator/releases ![image](https://hackmd.io/_uploads/r1ds8pH0T.png) - **Crie um novo namespace** chamado: `kafka` para o Operador de Cluster Strimzi Kafka: `kubectl create ns kafka` ![image](https://hackmd.io/_uploads/BJjFVhSAa.png) - **Modifique os arquivos de instalação** para fazer referência ao kafka namespace onde você instalará o Strimzi Kafka Cluster Operator: - **No Linux:** `sed -i 's/namespace: .*/namespace: kafka/' install/cluster-operator/*RoleBinding*.yaml` - **No windows, Powershell:** ```= $folderPath = "install\cluster-operator" # Caminho para a pasta contendo os arquivos # Lista todos os arquivos com o nome '*RoleBinding*.yaml' na pasta especificada $fileList = Get-ChildItem -Path $folderPath -Filter "*RoleBinding*.yaml" -File # Loop pelos arquivos foreach ($file in $fileList) { # Lê o conteúdo do arquivo $content = Get-Content $file.FullName # Substitui a string 'namespace: .*' por 'namespace: kafka' $newContent = $content -replace 'namespace: .+', 'namespace: kafka' # Escreve o novo conteúdo de volta para o arquivo $newContent | Set-Content $file.FullName } ``` - **Crie um novo namespace** `my-kafka-project` onde você implantará seu cluster Kafka: `kubectl create ns my-kafka-project` ![image](https://hackmd.io/_uploads/rJQcw2SRp.png) - **Edite o install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml** arquivo e defina a STRIMZI_NAMESPACE variável de ambiente como namespace `my-kafka-project` ![image](https://hackmd.io/_uploads/BJSEF2SRa.png) - Dê permissão ao Operador de Cluster para monitorar o **my-kafka-project** namespace: - `kubectl create -f install/cluster-operator/020-RoleBinding-strimzi-cluster-operator.yaml -n my-kafka-project` ![image](https://hackmd.io/_uploads/BJG5F2rCa.png) - `kubectl create -f install/cluster-operator/031-RoleBinding-strimzi-cluster-operator-entity-operator-delegation.yaml -n my-kafka-project` ![image](https://hackmd.io/_uploads/rJ2iKhSAa.png) - Implante os CRDs e recursos de controle de acesso baseado em função (RBAC) para gerenciar os CRDs: `kubectl create -f install/cluster-operator/ -n kafka` ![image](https://hackmd.io/_uploads/rJVDqhB0p.png) . . . ## Criando um cluster - **Iniciar o zookeeper**: `.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties` ![image](https://hackmd.io/_uploads/H1E-N6HC6.png) - **Iniciar o kafka**: `.\bin\windows\kafka-server-start.bat .\config\server.properties` ![image](https://hackmd.io/_uploads/SJG4EpBR6.png) - **Criar o topico**: `.\bin\windows\kafka-topics.bat --create --topic nome_do_topico --bootstrap-server localhost:9092` - **Listar os topicos** existentes: `.\bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092` ![image](https://hackmd.io/_uploads/H1P546r0a.png) - **Iniciar o producer**: `.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic topico-kafka-1803` ![image](https://hackmd.io/_uploads/rydyBTSCT.png) - **Iniciar o consumer**: `.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic topico-kafka-1803 --from-beginning` ![image](https://hackmd.io/_uploads/rk0kHpHCp.png) . . . - **Crie um namespace**: `kubectl create ns my-cluster` ![image](https://hackmd.io/_uploads/SJxjXkUCa.png) - Para listar namespaces: `kubectl get ns` ![image](https://hackmd.io/_uploads/B12bUyIR6.png) - **Crie o arquivo do novo cluster** Kafka: `my-cluster` com um ZooKeeper e um corretor Kafka. **my-kafka-project.yaml** ```yaml= apiVersion: kafka.strimzi.io/v1beta2 kind: Kafka metadata: name: my-cluster spec: kafka: replicas: 1 listeners: - name: plain port: 9092 type: internal tls: false - name: tls port: 9093 type: internal tls: true authentication: type: tls - name: external port: 9094 type: nodeport tls: false storage: type: jbod volumes: - id: 0 type: persistent-claim size: 100Gi deleteClaim: false config: offsets.topic.replication.factor: 1 transaction.state.log.replication.factor: 1 transaction.state.log.min.isr: 1 default.replication.factor: 1 min.insync.replicas: 1 zookeeper: replicas: 1 storage: type: persistent-claim size: 100Gi deleteClaim: false entityOperator: topicOperator: {} userOperator: {} ``` - **Para listar os clusters**: `kubectl get kafka` ![image](https://hackmd.io/_uploads/ryIwU1UCp.png) - **Instale o novo cluster**: `kubectl apply -f my-kafka-project.yaml` ![image](https://hackmd.io/_uploads/SJYb7JLC6.png) - **Aguarde a implantação do cluster**: `kubectl wait kafka/my-cluster --for=condition=Ready --timeout=300s -n my-kafka-project`