Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.

Malha de serviços do Sistema

Embora seja possível implantar configurações de Multi-Cluster Ops Manager, Multi-Cluster Sharded Cluster e Multi-Cluster Replica Set sem uma interface de rede, a abordagem recomendada (apresentada aqui) é aproveitar uma interface de serviço para lidar com a rede em vários Kubernetes. cluster. Para saber mais, consulte Como o operador do Kubernetes estabelece conectividade.

Esta página orienta você pelo processo de implantação e validação de uma malha de serviço Isio em vários clusters Kubernetes. O Isthio é apenas uma das muitas opções para implantar uma Service Mesh e não é compatível com o MongoDB.

Observação

O Istion não é suportado pelo MongoDB

O Isthio não é compatível com o MongoDB e é apenas uma das muitas ferramentas que você pode usar para implantar uma service interface nos clusters do Kubernetes.

Antes de começar, execute as seguintes tarefas:

  • Instalar kubectl.

  • Defina as variáveis de ambiente do K8S_CLUSTER_*_CONTEXT_NAME conforme explicado no guia Clusters GKE.

Você pode encontrar todo o código-fonte incluído no repositório do MongoDB Kubernetes Operator.

1

Execute o comando a seguir para clonar o repositório.

git clone https://github.com/mongodb/mongodb-kubernetes.gitcd mongodb-kubernetesgit checkout 1.4.0cd public/architectures
2

Instale a malha de serviço Istio para permitir a resolução de DNS entre clusters e a conectividade de rede entre clusters Kubernetes.

CTX_CLUSTER1=${K8S_CLUSTER_0_CONTEXT_NAME} \CTX_CLUSTER2=${K8S_CLUSTER_1_CONTEXT_NAME} \CTX_CLUSTER3=${K8S_CLUSTER_2_CONTEXT_NAME} \ISTIO_VERSION="1.20.2" \./install_istio_separate_network.sh
3

Rotule os namespaces do Kubernetes em cada cluster para habilitar a injeção de sidecar do Istion.

kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" label namespace "${OPERATOR_NAMESPACE}" istio-injection=enabled --overwritekubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" label namespace "${OPERATOR_NAMESPACE}" istio-injection=enabled --overwritekubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" label namespace "${OPERATOR_NAMESPACE}" istio-injection=enabled --overwrite kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" label namespace "${OM_NAMESPACE}" istio-injection=enabled --overwritekubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" label namespace "${OM_NAMESPACE}" istio-injection=enabled --overwritekubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" label namespace "${OM_NAMESPACE}" istio-injection=enabled --overwrite kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" label namespace "${MDB_NAMESPACE}" istio-injection=enabled --overwritekubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" label namespace "${MDB_NAMESPACE}" istio-injection=enabled --overwritekubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" label namespace "${MDB_NAMESPACE}" istio-injection=enabled --overwrite
4

Os scripts opcionais a seguir verificam se a interface de serviço está configurada corretamente para resolução e conectividade de DNS entre clusters.

  1. Crie um namespace Kubernetes para o teste de conectividade.

    kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" create namespace "connectivity-test"kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" label namespace "connectivity-test" istio-injection=enabled --overwrite kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" create namespace "connectivity-test"kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" label namespace "connectivity-test" istio-injection=enabled --overwrite kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" create namespace "connectivity-test"kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" label namespace "connectivity-test" istio-injection=enabled --overwrite
  2. Execute este script no cluster 0:

    kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOF apiVersion: apps/v1 kind: StatefulSet metadata: name: echoserver0 spec: replicas: 1 selector: matchLabels: app: echoserver0 template: metadata: labels: app: echoserver0 spec: containers: - image: k8s.gcr.io/echoserver:1.10 imagePullPolicy: Always name: echoserver0 ports: - containerPort: 8080EOF
  3. Execute este script no cluster 1:

    kubectl apply --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOF apiVersion: apps/v1 kind: StatefulSet metadata: name: echoserver1 spec: replicas: 1 selector: matchLabels: app: echoserver1 template: metadata: labels: app: echoserver1 spec: containers: - image: k8s.gcr.io/echoserver:1.10 imagePullPolicy: Always name: echoserver1 ports: - containerPort: 8080EOF
  4. Execute este script no cluster 2:

    kubectl apply --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOF apiVersion: apps/v1 kind: StatefulSet metadata: name: echoserver2 spec: replicas: 1 selector: matchLabels: app: echoserver2 template: metadata: labels: app: echoserver2 spec: containers: - image: k8s.gcr.io/echoserver:1.10 imagePullPolicy: Always name: echoserver2 ports: - containerPort: 8080EOF
  5. Execute este script para aguardar a criação do StatefulSets:

    kubectl wait --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "connectivity-test" --for=condition=ready pod -l statefulset.kubernetes.io/pod-name=echoserver0-0 --timeout=60skubectl wait --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "connectivity-test" --for=condition=ready pod -l statefulset.kubernetes.io/pod-name=echoserver1-0 --timeout=60skubectl wait --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "connectivity-test" --for=condition=ready pod -l statefulset.kubernetes.io/pod-name=echoserver2-0 --timeout=60s
  6. Criar serviço de Pod no cluster 0:

    kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOFapiVersion: v1kind: Servicemetadata: name: echoserver0-0spec: ports: - port: 8080 targetPort: 8080 protocol: TCP selector: statefulset.kubernetes.io/pod-name: "echoserver0-0"EOF
  7. Criar serviço de Pod no cluster 1:

    kubectl apply --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOFapiVersion: v1kind: Servicemetadata: name: echoserver1-0spec: ports: - port: 8080 targetPort: 8080 protocol: TCP selector: statefulset.kubernetes.io/pod-name: "echoserver1-0"EOF
  8. Criar serviço de Pod no cluster 2:

    kubectl apply --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOFapiVersion: v1kind: Servicemetadata: name: echoserver2-0spec: ports: - port: 8080 targetPort: 8080 protocol: TCP selector: statefulset.kubernetes.io/pod-name: "echoserver2-0"EOF
  9. Criar serviço de round robin no cluster 0:

    kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOFapiVersion: v1kind: Servicemetadata: name: echoserverspec: ports: - port: 8080 targetPort: 8080 protocol: TCP selector: app: echoserver0EOF
  10. Criar serviço de round robin no cluster 1:

    kubectl apply --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOFapiVersion: v1kind: Servicemetadata: name: echoserverspec: ports: - port: 8080 targetPort: 8080 protocol: TCP selector: app: echoserver1EOF
  11. Criar serviço de round robin no cluster 2:

    kubectl apply --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "connectivity-test" -f - <<EOFapiVersion: v1kind: Servicemetadata: name: echoserverspec: ports: - port: 8080 targetPort: 8080 protocol: TCP selector: app: echoserver2EOF
  12. Verifique o Pod 0 do cluster 1:

    source_cluster=${K8S_CLUSTER_1_CONTEXT_NAME}target_pod="echoserver0-0"source_pod="echoserver1-0"target_url="http://${target_pod}.connectivity-test.svc.cluster.local:8080"echo "Checking cross-cluster DNS resolution and connectivity from ${source_pod} in ${source_cluster} to ${target_pod}"out=$(kubectl exec --context "${source_cluster}" -n "connectivity-test" "${source_pod}" -- \ /bin/bash -c "curl -v ${target_url}" 2>&1); if grep "Hostname: ${target_pod}" &>/dev/null <<< "${out}"then echo "SUCCESS"else echo "ERROR: ${out}" return 1fi
  13. Verifique o Pod 1 do cluster 0:

    source_cluster=${K8S_CLUSTER_0_CONTEXT_NAME}target_pod="echoserver1-0"source_pod="echoserver0-0"target_url="http://${target_pod}.connectivity-test.svc.cluster.local:8080"echo "Checking cross-cluster DNS resolution and connectivity from ${source_pod} in ${source_cluster} to ${target_pod}"out=$(kubectl exec --context "${source_cluster}" -n "connectivity-test" "${source_pod}" -- \ /bin/bash -c "curl -v ${target_url}" 2>&1); if grep "Hostname: ${target_pod}" &>/dev/null <<< "${out}"then echo "SUCCESS"else echo "ERROR: ${out}" return 1fi
  14. Verifique o Pod 1 do cluster 2:

    source_cluster=${K8S_CLUSTER_2_CONTEXT_NAME}target_pod="echoserver1-0"source_pod="echoserver2-0"target_url="http://${target_pod}.connectivity-test.svc.cluster.local:8080"echo "Checking cross-cluster DNS resolution and connectivity from ${source_pod} in ${source_cluster} to ${target_pod}"out=$(kubectl exec --context "${source_cluster}" -n "connectivity-test" "${source_pod}" -- \ /bin/bash -c "curl -v ${target_url}" 2>&1); if grep "Hostname: ${target_pod}" &>/dev/null <<< "${out}"then echo "SUCCESS"else echo "ERROR: ${out}" return 1fi
  15. Verifique o Pod 2 do cluster 0:

    source_cluster=${K8S_CLUSTER_0_CONTEXT_NAME}target_pod="echoserver2-0"source_pod="echoserver0-0"target_url="http://${target_pod}.connectivity-test.svc.cluster.local:8080"echo "Checking cross-cluster DNS resolution and connectivity from ${source_pod} in ${source_cluster} to ${target_pod}"out=$(kubectl exec --context "${source_cluster}" -n "connectivity-test" "${source_pod}" -- \ /bin/bash -c "curl -v ${target_url}" 2>&1); if grep "Hostname: ${target_pod}" &>/dev/null <<< "${out}"then echo "SUCCESS"else echo "ERROR: ${out}" return 1fi
  16. Execute o script de limpeza:

    kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "connectivity-test" delete statefulset echoserver0kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "connectivity-test" delete statefulset echoserver1kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "connectivity-test" delete statefulset echoserver2kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "connectivity-test" delete service echoserverkubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "connectivity-test" delete service echoserverkubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "connectivity-test" delete service echoserverkubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "connectivity-test" delete service echoserver0-0kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "connectivity-test" delete service echoserver1-0kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "connectivity-test" delete service echoserver2-0kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" delete ns "connectivity-test"kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" delete ns "connectivity-test"kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" delete ns "connectivity-test"