본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

kubectl apply

원문 보기 위키 갱신

kubectl과 정적 매니페스트(static manifests)를 사용해 cert-manager를 설치하는 방법을 배워볼게요.

출처: 문서

본문

사전 요구 사항

  • kubectl 버전 >= v1.19.0 (https://kubernetes.io/docs/tasks/tools/) 을 설치합니다. (그렇지 않으면 CRD 업데이트에 문제가 생길 수 있습니다 - v0.16 업그레이드 노트 (/docs/releases/upgrading/upgrading-0.15-0.16/#issue-with-older-versions-of-kubectl) 참조)

  • 지원되는 버전의 Kubernetes 또는 OpenShift (/docs/releases/) 를 설치합니다.

  • 클라우드 플랫폼에서 Kubernetes를 사용한다면 Kubernetes 플랫폼 제공자 호환성 (/docs/installation/compatibility/) 문서를 읽어보세요.

단계

1. cert-manager 릴리스 매니페스트에서 설치

모든 리소스(CustomResourceDefinitions와 cert-manager, cainjector, webhook 구성 요소)가 단일 YAML 매니페스트 파일에 포함되어 있습니다:

모든 cert-manager 구성 요소를 설치합니다:

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.21.2/cert-manager.yaml

기본적으로 cert-manager는 cert-manager 네임스페이스에 설치됩니다. cert-manager를 다른 네임스페이스에서 실행하는 것도 가능하지만, 배포 매니페스트를 수정해야 합니다.

cert-manager를 설치한 후 cert-manager 네임스페이스에서 실행 중인 포드를 확인하여 제대로 배포되었는지 확인할 수 있습니다:

$ kubectl get pods --namespace cert-manager

NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-5c6866597-zw7kh               1/1     Running   0          2m
cert-manager-cainjector-577f6d9fd7-tr77l   1/1     Running   0          2m
cert-manager-webhook-787858fcdb-nlzsq      1/1     Running   0          2m

cert-manager, cert-manager-cainjector, cert-manager-webhook 포드가 Running 상태인 것을 확인해야 합니다. webhook은 다른 것들보다 프로비저닝에 조금 더 오래 걸릴 수 있습니다.

문제가 발생하면 먼저 FAQ (/docs/faq/) 를 확인하세요.

2. (선택 사항) cert-manager webhook가 준비될 때까지 대기

webhook 구성 요소는 시작하고 Kubernetes API 서버가 webhook의 인증서를 신뢰하게 만드는 데 시간이 걸릴 수 있습니다.

먼저 cmctl이 설치되어 있는지 확인합니다 (/docs/reference/cmctl/#installation) .

cmctl은 Kubernetes 클러스터에 대해 dry-run 인증서 생성 검사를 수행합니다. 성공하면 The cert-manager API is ready 메시지가 표시됩니다.

$ cmctl check api
The cert-manager API is ready

이 명령은 검사가 성공할 때까지 대기하는 데에도 사용할 수 있습니다. 다음은 cert-manager가 설치되는 동시에 명령을 실행한 출력 예시입니다:

$ cmctl check api --wait=2m
Not ready: the cert-manager CRDs are not yet installed on the Kubernetes API server
Not ready: the cert-manager CRDs are not yet installed on the Kubernetes API server
Not ready: the cert-manager webhook deployment is not ready yet
Not ready: the cert-manager webhook deployment is not ready yet
Not ready: the cert-manager webhook deployment is not ready yet
Not ready: the cert-manager webhook deployment is not ready yet
The cert-manager API is ready

2. (선택 사항) 설치를 엔드투엔드로 검증

설치를 완전히 검증하는 가장 좋은 방법은 테스트 인증서를 발급하는 것입니다. 이를 위해 테스트 네임스페이스에 자체 서명(self-signed) issuer와 인증서 리소스를 생성합니다.

cat  test-resources.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: cert-manager-test
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: test-selfsigned
  namespace: cert-manager-test
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: selfsigned-cert
  namespace: cert-manager-test
spec:
  dnsNames:
    - example.com
  secretName: selfsigned-cert-tls
  issuerRef:
    name: test-selfsigned
EOF

테스트 리소스를 생성합니다.

kubectl apply -f test-resources.yaml

새로 생성된 인증서의 상태를 확인합니다. cert-manager가 인증서 요청을 처리하기 전에 몇 초 기다려야 할 수 있습니다.

$ kubectl describe certificate -n cert-manager-test

...
Spec:
  Common Name:  example.com
  Issuer Ref:
    Name:       test-selfsigned
  Secret Name:  selfsigned-cert-tls
Status:
  Conditions:
    Last Transition Time:  2019-01-29T17:34:30Z
    Message:               Certificate is up to date and has not expired
    Reason:                Ready
    Status:                True
    Type:                  Ready
  Not After:               2019-04-29T17:34:29Z
Events:
  Type    Reason      Age   From          Message
  ----    ------      ----  ----          -------
  Normal  CertIssued  4s    cert-manager  Certificate issued successfully

테스트 리소스를 정리합니다.

kubectl delete -f test-resources.yaml

위의 모든 단계가 오류 없이 완료되었다면 설치가 성공적으로 완료된 것입니다!

제거하기

경고: cert-manager를 제거할 때는 항상 설치할 때와 동일한 프로세스를 역순으로 사용해야 합니다. cert-manager가 정적 매니페스트에서 설치되었든 Helm에서 설치되었든 아래 프로세스에서 벗어나면 문제가 발생하고 잠재적으로 고장난 상태가 될 수 있습니다. 이를 방지하기 위해 제거할 때 아래 단계를 반드시 따르세요.

계속하기 전에 사용자가 생성한 불필요한 cert-manager 리소스가 삭제되었는지 확인하세요. 다음 명령으로 기존 리소스를 확인할 수 있습니다:

kubectl get Issuers,ClusterIssuers,Certificates,CertificateRequests,Orders,Challenges --all-namespaces

cert-manager를 제거하기 전에 이 모든 리소스를 삭제하는 것이 좋습니다. 나중에 다시 설치할 계획이고 일부 커스텀 리소스를 잃고 싶지 않다면 유지해도 됩니다. 그러나 이는 finalizer에 문제를 일으킬 수 있습니다. Challenges 같은 일부 리소스는 pending 상태에 빠지는 것을 피하기 위해 삭제해야 합니다 (/docs/installation/kubectl/#namespace-stuck-in-terminating-state) .

불필요한 리소스를 삭제한 후에는 설치 방식에 따라 결정된 절차를 사용해 cert-manager를 제거할 준비가 된 것입니다.

경고: cert-manager를 제거하거나 단순히 Certificate 리소스를 삭제하면, cert-manager가 설정한 metadata.ownerReferences가 있는 TLS Secret이 삭제될 수 있습니다. --enable-certificate-owner-ref 컨트롤러 플래그를 사용해 Secret에 owner reference를 추가할지 제어할 수 있습니다. 기본적으로 이 플래그는 false로 설정되어 있어 owner reference가 추가되지 않습니다. 그러나 cert-manager v1.8 이하에서는 플래그 값을 true에서 false로 변경해도 기존 owner reference가 제거되지 않았습니다. 이 동작은 cert-manager v1.8에서 수정되었습니다. owner reference가 실제로 제거되었는지 확인해 보세요.

일반 매니페스트로 제거하기

일반 매니페스트로 설치한 환경에서 제거하는 경우 kubectl의 delete 명령을 사용해 설치 프로세스를 역순으로 실행하면 됩니다.

현재 실행 중인 버전 vX.Y.Z에 대한 링크를 사용해 설치 매니페스트를 삭제합니다:

경고: 이 명령은 설치된 cert-manager CRD도 제거합니다. 모든 cert-manager 리소스(예: certificates.cert-manager.io 리소스)는 Kubernetes의 가비지 컬렉터에 의해 제거됩니다. CustomResourceDefinition을 삭제하면 어떤 커스텀 리소스도 유지할 수 없습니다. 리소스를 유지하려면 CustomResourceDefinition을 별도로 관리해야 합니다.

kubectl delete -f https://github.com/cert-manager/cert-manager/releases/download/vX.Y.Z/cert-manager.yaml

고아가 된 lease 삭제하기

참고: cert-manager는 리더 선출을 위해 Kubernetes Lease (https://kubernetes.io/docs/concepts/architecture/leases/) 객체를 사용하며, 이는 기본적으로 활성화되어 있습니다. 이 lease는 일반적으로 kube-system 네임스페이스에 생성되지만 네임스페이스는 구성할 수 있습니다. cert-manager를 제거할 때 자동으로 제거되지 않습니다. 수동으로 안전하게 삭제할 수 있습니다:

kubectl delete lease -n  cert-manager-cainjector-leader-election cert-manager-controller

<namespace>를 리더 선출 lease가 생성된 네임스페이스(기본값은 kube-system)로 바꾸세요.

Terminating 상태에 갇힌 네임스페이스

cert-manager 설치를 먼저 삭제하지 않고 네임스페이스를 삭제하도록 표시하면 네임스페이스가 terminating 상태에 갇힐 수 있습니다. 이는 일반적으로 APIService (https://kubernetes.io/docs/tasks/access-kubernetes-api/setup-extension-api-server) 리소스가 여전히 존재하지만 webhook가 더 이상 실행되지 않아 더 이상 접근할 수 없기 때문입니다. 이를 해결하려면 위 명령을 올바르게 실행했는지 확인하고, 여전히 문제가 발생한다면 다음을 실행하세요:

kubectl delete apiservice v1beta1.webhook.cert-manager.io

pending 챌린지 삭제하기

finalizer를 완료할 수 없고 Kubernetes가 cert-manager 컨트롤러가 끝나기를 기다리고 있을 때 Challenge가 pending 상태에 갇힐 수 있습니다. 이는 컨트롤러가 더 이상 실행되어 플래그를 제거하지 않을 때 발생하며, 리소스가 대기하도록 정의되어 있기 때문입니다. 컨트롤러가 하는 일을 수동으로 수행하면 이 문제를 해결할 수 있습니다.

먼저 기존 cert-manager webhook 구성을 삭제합니다(있는 경우):

kubectl delete mutatingwebhookconfigurations cert-manager-webhook
kubectl delete validatingwebhookconfigurations cert-manager-webhook

그런 다음 챌린지 리소스를 편집하여 .metadata.finalizers 필드를 빈 목록으로 변경합니다:

kubectl edit challenge 

더 알아보기 (Learn more)