Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Menu Docs
Página inicial do Docs
/
Operador de Kubernetes empresarial
/ /

Certificados TLS

Esta seção fornece orientações sobre a criação de certificados TLS para cada componente do MongoDB e a criação de segredos do Kubernetes em cada um dos seus clusters do Kubernetes para montar os certificados TLS com segurança nos pods do Kubernetes apropriados.

The process outlined below utilizes Cert Manager for creating the TLS certificates. However, please note that this is an opinionated guide, and CertManager is not supported by MongoDB. Moreover, CertManager is only one of many ways in which you can add TLS certificates to your Kubernetes clusters. Additionally, self-signed certificates may not be suitable for production deployments, depending on the security requirements of your organization. If you require publicly trusted certificates please configure your Issuer accordingly or provide the TLS certificate directly. To learn more, see Set Up a cert-manager Integration.

Antes de começar, execute as seguintes tarefas:

  • Instale o kubectl.

  • Instale o Helm.

  • 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
1helm repo add jetstack https://charts.jetstack.io --force-update
2
1helm install \
2 cert-manager jetstack/cert-manager \
3 --kube-context "${K8S_CLUSTER_0_CONTEXT_NAME}" \
4 --namespace cert-manager \
5 --create-namespace \
6 --set crds.enabled=true
3
1kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -f - <<EOF
2apiVersion: cert-manager.io/v1
3kind: ClusterIssuer
4metadata:
5 name: selfsigned-cluster-issuer
6spec:
7 selfSigned: {}
8EOF
9
10kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" wait --for=condition=Ready clusterissuer selfsigned-cluster-issuer
11
12kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -f - <<EOF
13apiVersion: cert-manager.io/v1
14kind: Certificate
15metadata:
16 name: my-selfsigned-ca
17 namespace: cert-manager
18spec:
19 isCA: true
20 commonName: my-selfsigned-ca
21 secretName: root-secret
22 privateKey:
23 algorithm: ECDSA
24 size: 256
25 issuerRef:
26 name: selfsigned-cluster-issuer
27 kind: ClusterIssuer
28EOF
29
30kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" wait --for=condition=Ready -n cert-manager certificate my-selfsigned-ca
31
32kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -f - <<EOF
33apiVersion: cert-manager.io/v1
34kind: ClusterIssuer
35metadata:
36 name: my-ca-issuer
37spec:
38 ca:
39 secretName: root-secret
40EOF
41
42kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" wait --for=condition=Ready clusterissuer my-ca-issuer
4
1kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -f - <<EOF
2apiVersion: cert-manager.io/v1
3kind: Certificate
4metadata:
5 name: test-selfsigned-cert
6 namespace: cert-manager
7spec:
8 dnsNames:
9 - example.com
10 secretName: test-selfsigned-cert-tls
11 issuerRef:
12 name: my-ca-issuer
13 kind: ClusterIssuer
14EOF
15
16kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" wait -n cert-manager --for=condition=Ready certificate test-selfsigned-cert
17
18kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" delete -n cert-manager certificate test-selfsigned-cert
5
1mkdir -p certs
2
3kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" get secret root-secret -n cert-manager -o jsonpath="{.data['ca\.crt']}" | base64 --decode > certs/ca.crt
4kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" create cm ca-issuer -n "${MDB_NAMESPACE}" --from-file=ca-pem=certs/ca.crt --from-file=mms-ca.crt=certs/ca.crt
5kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" create cm ca-issuer -n "${OM_NAMESPACE}" --from-file=ca-pem=certs/ca.crt --from-file=mms-ca.crt=certs/ca.crt

Nesta página