cert-manager simplifies and automates the management of security certificates for Kubernetes. The following procedure describes how to configure cert-manager to generate certificates for MongoDB Kubernetes Operator resources.
전제 조건
객체 를 사용하여 복제본 세트를 배포하려면 다음을 수행합니다. ,다음을 수행해야 합니다.
Kubernetes Operator용 MongoDB 컨트롤러가 있거나 설치되어 있어야 합니다.
Kubernetes Operator ConfigMap을 생성하거나 작성합니다.
Kubernetes Operator에 대한 자격 증명을 생성하거나 다른 시크릿 저장 도구를 구성합니다.
참고
단일 클러스터 Kubernetes 배포에 시크릿이 저장되지 않도록 하려면 모든 시크릿 을 시크릿 저장 도구로 마이그레이션 할 수 있습니다. 여러 Kubernetes 클러스터에 대한 배포는 HashiCorp Vault와 같은 시크릿 저장 도구에 시크릿을 저장하는 것을 지원하지 않습니다.
다음 구성 요소 각각에 대해 하나의 TLS 인증서를 생성합니다.
복제본 세트입니다. 복제본 세트의 구성원을 인증서에 호스팅하는 각 Kubernetes Pod에 대해 SAN을 추가했는지 확인하세요.
TLS 인증서에서 각 포드의 SAN은 다음 형식을 사용해야 합니다.
<pod-name>.<metadata.name>-svc.<namespace>.svc.cluster.local 중요
If you're using an ACME based service provider such as Let's Encrypt to issue TLS certificates, the provider might prohibit you from adding the Pod's default FQDNs (
*.svc.cluster.local) to SANs in the certificate.ACME 기반 인증서를 사용하려면 복제본 세트 리소스에 대한 인증서를 구성해야 합니다. 자세히 학습 절차의 ACME 기반 TLS 인증서에 대한 단계를 참조하세요.
프로젝트의 MongoDB Agent입니다. MongoDB Agent 인증서의 경우 다음 요구 사항을 충족하는지 확인하세요.
TLS 인증서의 일반 이름이 비어 있지 않습니다.
각 TLS 인증서의 결합된 조직 및 조직 구성 단위는 복제본 세트 멤버에 대한 TLS 인증서의 조직 및 조직 구성 단위와 다릅니다.
You must have the CA certificate file and name it
ca-pem.TLS 인증서에 서명할 때 사용한 키가 있어야 합니다.
중요
Kubernetes Operator는 kubernetes.io/tls 시크릿을 사용하여 Ops Manager 및 MongoDB 리소스에 대한 TLS 인증서와 비공개 키를 저장 . Kubernetes Operator 버전 1.17.0부터 Kubernetes Operator는 Opaque 시크릿으로 저장된 연결된 PEM 파일을 지원 하지 않습니다.
객체 를 사용하여 복제본 세트를 배포하려면 다음을 수행합니다. ,다음을 수행해야 합니다.
Kubernetes Operator용 MongoDB 컨트롤러가 있거나 설치되어 있어야 합니다.
Kubernetes Operator ConfigMap을 생성하거나 작성합니다.
Kubernetes Operator에 대한 자격 증명을 생성하거나 다른 시크릿 저장 도구를 구성합니다.
참고
단일 클러스터 Kubernetes 배포에 시크릿이 저장되지 않도록 하려면 모든 시크릿 을 시크릿 저장 도구로 마이그레이션 할 수 있습니다. 여러 Kubernetes 클러스터에 대한 배포는 HashiCorp Vault와 같은 시크릿 저장 도구에 시크릿을 저장하는 것을 지원하지 않습니다.
절차
CA 시크릿 을 생성합니다.
참고
The following steps assume that you have already created a custom CA along with the corresponding tls.key private key and tls.crt signed certificate.
CA 데이터를 저장할 시크릿을 생성합니다.
apiVersion: v1 kind: Secret metadata: name: ca-key-pair namespace: <namespace> data: tls.crt: <your-CA-certificate> tls.key: <your-CA-private-key>
사용자 지정 CA 인증서에 인증서를 추가합니다.
If your Ops Manager TLS certificate is signed by a custom CA, the CA certificate must also contain additional certificates that allow Ops Manager Backup Daemon to download MongoDB binaries from the Internet. To create the TLS certificate(s), create a ConfigMap to hold the CA certificate:
중요
Kubernetes 연산자는 ConfigMap에서 Ops Manager 인증서의 이름이 mms-ca.crt 이어야 합니다.
Obtain the entire TLS certificate chain for Ops Manager from
downloads.mongodb.com. The followingopensslcommand outputs the certificate in the chain to your current working directory, in.crtformat:openssl s_client -showcerts -verify 2 \ -connect downloads.mongodb.com:443 -servername downloads.mongodb.com < /dev/null \ | awk '/BEGIN/,/END/{ if(/BEGIN/){a++}; out="cert"a".crt"; print >out}' Concatenate your CA's certificate file for Ops Manager with the entire TLS certificate chain from
downloads.mongodb.comthat you obtained in the previous step:cat <custom_ca_cert.pem> cert2.crt cert3.crt cert4.crt >> mms-ca.crt 참고
자리 표시자
<custom_ca_cert.pem>를 사용자 지정 CA 인증서 PEM 파일 로 바꿉니다.cert1.crt파일 포함하지 않아야 하는 MongoDB 의 서버 인증서이므로 포함하지 마세요.
ConfigMap 만들기 MongoDB Ops Manager의 경우:
kubectl create configmap om-http-cert-ca --from-file="mms-ca.crt"
Create a CA ConfigMap
Create a ConfigMap containing your CA. It must have two fields, ca-pem and mms-ca.crt, both pointing to your CA certificate. Replace <CA-certificate> with the path to your CA certificate.
kubectl create cm ca-issuer --from-file=ca-pem=<CA-certificate> \ --from-file=mms-ca.crt=<CA-certificate>
MongoDB 리소스에 대한 인증서 만들기
생성된 인증서로 MongoDB 리소스를 보호하려면 리소스 자체와 MongoDB Agent 모두에 대한 인증서를 생성해야 합니다.
MongoDB 리소스 인증서를 생성합니다. 다음 예제에서는
my-replica-set이라는 이름의 복제본 세트와 세 명의 멤버가 있다고 가정합니다.참고
spec.issuerRef.name매개변수는 이전에 생성된 CA ConfigMap을 참고합니다.apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: my-replica-set-certificate namespace: mongodb spec: dnsNames: - my-replica-set-0 - my-replica-set-0.my-replica-set-svc.mongodb.svc.cluster.local - my-replica-set-1 - my-replica-set-1.my-replica-set-svc.mongodb.svc.cluster.local - my-replica-set-2 - my-replica-set-2.my-replica-set-svc.mongodb.svc.cluster.local duration: 240h0m0s issuerRef: name: ca-issuer renewBefore: 120h0m0s secretName: mdb-my-replica-set-cert usages: - server auth - client auth 샤딩된 클러스터의 경우 각 StatefulSet에 대해 하나의 인증서를 생성해야 합니다.. 샤딩된 클러스터 구성에 대해 자세히 학습하려면 샤드 클러스터 배포를 참조하세요.
MongoDB Agent 인증서를 생성합니다.
참고
spec.issuerRef.name매개변수는 이전에 생성된 CA ConfigMap을 참고합니다.apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: agent-certs namespace: mongodb spec: commonName: automation dnsNames: - automation duration: 240h0m0s issuerRef: name: ca-issuer renewBefore: 120h0m0s secretName: mdb-my-replica-set-agent-certs usages: - digital signature - key encipherment - client auth subject: countries: - US localities: - NY organizationalUnits: - a-1635241837-m5yb81lfnrz organizations: - cluster.local-agent provinces: - NY MongoDB 리소스를 생성합니다.
참고
spec.security.tls.ca매개변수를 지정하지 않은 상태로 두면 기본값은{replica-set}-ca입니다.apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: my-replica-set namespace: mongodb spec: type: ReplicaSet members: 3 version: 8.0.0 opsManager: configMapRef: name: my-project credentials: my-credentials security: certsSecretPrefix: mdb authentication: enabled: true modes: - X509 tls: ca: ca-issuer enabled: true
TLS를 사용하여 Ops Manager 및 AppDB에 대한 인증서 만들기
Ops Manager 리소스를 보호하려면 먼저 Ops Manager 및 AppDB에 대한 인증서를 생성한 다음 Ops Manager 리소스를 생성해야 합니다.
Ops Manager 인증서를 만듭니다.
참고
spec.issuerRef.name매개변수는 이전에 생성된 CA ConfigMap을 참고합니다.apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: cert-for-ops-manager namespace: mongodb spec: dnsNames: - om-with-https-svc.mongodb.svc.cluster.local duration: 240h0m0s issuerRef: name: ca-issuer renewBefore: 120h0m0s secretName: mdb-om-with-https-cert usages: - server auth - client auth AppDB 인증서를 생성합니다.
참고
spec.issuerRef.name매개변수는 이전에 생성된 CA ConfigMap을 참고합니다.apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: appdb-om-with-https-db-cert namespace: mongodb spec: dnsNames: - om-with-https-db-0 - om-with-https-db-0.om-with-https-db-svc.mongodb.svc.cluster.local - om-with-https-db-1 - om-with-https-db-1.om-with-https-db-svc.mongodb.svc.cluster.local - om-with-https-db-2 - om-with-https-db-2.om-with-https-db-svc.mongodb.svc.cluster.local duration: 240h0m0s issuerRef: name: ca-issuer renewBefore: 120h0m0s secretName: appdb-om-with-https-db-cert usages: - server auth - client auth Ops Manager 리소스를 만듭니다:
apiVersion: mongodb.com/v1 kind: MongoDBOpsManager metadata: name: om-with-https namespace: mongodb spec: adminCredentials: ops-manager-admin-secret version: "8.0.0" applicationDatabase: members: 3 security: certsSecretPrefix: appdb tls: ca: ca-issuer version: 8.0.0-ubi8 replicas: 1 security: certsSecretPrefix: mdb tls: ca: ca-issuer
인증서 갱신
cert-manager는 다음과 같은 상황에서 인증서를 갱신합니다.
인증서는
spec.duration및spec.renewBefore필드에 따라 만료됩니다.인증서가 포함된 비밀을 삭제합니다. 이 경우 cert-manager는 인증서 사용자 지정 리소스의 구성에 따라 시크릿을 다시 생성합니다.
인증서 사용자 지정 리소스의 구성을 변경합니다. 이 경우 cert-manager는 구성 변경을 감지하면 인증서가 포함된 시크릿을 다시 생성합니다.