티스토리 뷰

사용자 데이터의 온라인 보안 및 개인 정보 보호는 회사로서의 Fruit Smoothies의 주요 관심사이다. 평가 웹 사이트에서는 모든 고객에게 HTTPS 연결을 허용하는 것이 중요하다. NGINX 인그레스 컨트롤러는 TLS 종료를 지원하며 HTTPS에 대한 인증서를 검색하고 구성하는 여러 가지 방법을 제공한다. 이 실습에서는 자동 Let's Encrypt 인증서 생성 및 관리 기능을 제공하는 cert-manager를 사용하는 방법을 보여 준다.

이번 실습에서 다음을 수행한다.

  • Helm을 사용하여 인증서 관리자 배포
  • Let's Encrypt용 ClusterIssuer 리소스 배포
  • 수신 시 평가 웹 서비스에 대해 SSL/TLS 사용
  • 애플리케이션 테스트

 

 

 

인증서 관리자 배포

cert-manager는 클라우드 네이티브 환경에서 인증서 관리를 자동화하도록 해주는 Kubernetes 인증서 관리 컨트롤러이다. 인증서 관리자는 Let's Encrypt, HashiCorp Vault, Venafi, 간단한 서명 키 쌍 또는 자체 서명된 인증서를 비롯한 다양한 소스를 지원한다. cert-manager를 사용하여 웹 사이트의 인증서가 유효하고 최신 상태인지 확인하고, 인증서가 만료되기 전에 구성된 시간에 인증서를 갱신한다.

인증서 관리자는 Kubernetes 사용자 지정 리소스를 사용한다. Kubernetes 사용자 지정 리소스는 Kubernetes API를 확장하거나 API를 클러스터에 도입하는 데 사용할 수 있는 오브젝트이다. CRD(Custom Resource Definition) 파일을 사용하여 오브젝트 종류를 정의하고 API 서버에서 오브젝트의 수명 주기를 관리한다.

여기에서는 Helm을 사용하여 인증서 관리자를 설치한 다음, 인증서 발급자로 Let's Encrypt를 사용하도록 구성한다.

 

1. 먼저 인증서 관리자에 대한 네임스페이스를 만들어 보겠다.kubectl create namespace cert-manager

kim@Azure:~$ kubectl create namespace cert-manager
namespace/cert-manager created

 

2. Jetstack Helm 리포지토리를 사용하여 인증서 관리자를 찾아 설치한다. 먼저 아래 코드를 실행하여 Jetstack Helm 리포지토리를 추가한다.

helm repo add jetstack https://charts.jetstack.io
helm repo update
kim@Azure:~$ helm repo add jetstack https://charts.jetstack.io
"jetstack" has been added to your repositories
kim@Azure:~$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "jetstack" chart repository
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈

 

3. 다음 명령을 실행해 인증서 관리자 CRD를 배포하여 인증서 관리자를 설치한다.

kubectl apply --validate=false -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.14/deploy/manifests/00-crds.yaml
kim@Azure:~$ kubectl apply --validate=false -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.14/deploy/manifests/00-crds.yaml
Warning: apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
customresourcedefinition.apiextensions.k8s.io/certificaterequests.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/certificates.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/challenges.acme.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/clusterissuers.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/issuers.cert-manager.io created
customresourcedefinition.apiextensions.k8s.io/orders.acme.cert-manager.io created

 

4. 다음 명령을 실행해 인증서 관리자 Helm 차트를 설치한다.

helm install cert-manager \
--namespace cert-manager \
--version v0.14.0 \ jetstack/cert-manager

 

5. 설치가 완료되면 아래 예제와 유사한 출력이 표시된다.

kim@Azure:~$ helm install cert-manager \
>     --namespace cert-manager \
>     --version v0.14.0 \
>     jetstack/cert-manager
W0523 01:45:42.429952     218 warnings.go:67] rbac.authorization.k8s.io/v1beta1 ClusterRole is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRole
<중략>
W0523 01:45:45.180452     218 warnings.go:67] admissionregistration.k8s.io/v1beta1 ValidatingWebhookConfiguration is deprecated in v1.16+, unavailable in v1.22+; use admissionregistration.k8s.io/v1 ValidatingWebhookConfiguration
NAME: cert-manager
LAST DEPLOYED: Sun May 23 01:45:41 2021
NAMESPACE: cert-manager
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
cert-manager has been deployed successfully!


In order to begin issuing certificates, you will need to set up a ClusterIssuer
or Issuer resource (for example, by creating a 'letsencrypt-staging' issuer).


More information on the different types of issuers and how to configure them
can be found in our documentation:


https://docs.cert-manager.io/en/latest/reference/issuers.html


For information on how to configure cert-manager to automatically provision
Certificates for Ingress resources, take a look at the `ingress-shim`
documentation:


https://docs.cert-manager.io/en/latest/reference/ingress-shim.html

 

6. 실행 중인 Pod의 cert-manager 네임스페이스를 확인하여 설치를 검증한다.

kubectl get pods --namespace cert-manager

cert-manager, cert-manager-cainjector, cert-manager-webhook 파드가 Running 상태인 것을 확인할 수 있다. TLS 자산에 필요한 웹 훅을 프로비저닝하는 데 몇 분 정도 걸릴 수도 있다.

kim@Azure:~$ kubectl get pods --namespace cert-manager
NAME                                      READY   STATUS    RESTARTS   AGE
cert-manager-56c84569c9-4vw62             1/1     Running   0          98s
cert-manager-cainjector-97596cdd4-lrxpv   1/1     Running   0          98s
cert-manager-webhook-54bff44696-r9xb8     1/1     Running   0          98s

 

Let's Encrypt용 ClusterIssuer 리소스 배포

인증서 관리자를 사용하면 웹 사이트의 인증서가 유효하고 최신 상태인지 확인하고, 심지어 인증서가 만료되기 전에 구성된 시간에 인증서 갱신을 시도한다. 그러나 인증서 발급 프로세스를 시작하려면 먼저 ClusterIssuer를 설정해야 한다. 클러스터 발급자는 Let's Encrypt와 같은 인증서 발급 서비스에 대한 인터페이스의 역할을 한다.

Let's Encrypt는 TLS 인증서를 제공하는 비영리 인증 기관이다. Let's Encrypt를 사용하면 HTTP 서버를 설정하고 브라우저에서 신뢰할 수 있는 인증서를 자동으로 가져올 수 있다. 인증서를 검색하고 설치하는 프로세스는 사용자 개입 없이 완전히 자동화되며 웹 서버에서 인증서 관리 에이전트를 실행하여 관리된다. Let's Encrypt에 대한 자세한 내용은 이 모듈의 끝에 있는 자세한 정보 섹션을 참조한다.

 

1. 통합 편집기를 사용하여 cluster-issuer.yaml이라는 이름의 파일을 편집한다.

code cluster-issuer.yaml

 

2. 파일의 기존 콘텐츠를 다음 텍스트로 대체한다.

apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
  name: letsencrypt
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: <your email> # IMPORTANT: Replace with a valid email from your organization
    privateKeySecretRef:
      name: letsencrypt
    solvers:
    - http01:
        ingress:
          class: nginx

 

3. 파일을 저장하려면 Ctrl+S를 선택한다. 편집기를 닫으려면 Ctrl+Q를 선택한다.email 키에서 <your email>을 조직의 유효한 인증 관리자 메일로 대체하여 값을 업데이트한다.

 

4. kubectl apply 명령을 사용하여 구성을 적용한다. ratingsapp 네임스페이스에 클러스터 발급자 구성을 배포한다.

kubectl apply \
--namespace ratingsapp \
-f cluster-issuer.yaml

 

다음 예제와 비슷한 출력이 표시된다.

kim@Azure:~$ kubectl apply \
>     --namespace ratingsapp \
>     -f cluster-issuer.yaml
clusterissuer.cert-manager.io/letsencrypt created

 

 

인그레스의 평가 웹 서비스에 대한 SSL/TLS 사용

구성의 마지막 부분은 평가 웹 서비스에 대한 Kubernetes 인그레스 파일에서 SSL/TLS를 사용하도록 구성하는 것이다.

 

1. 통합 편집기를 사용하여 ratings-web-ingress.yaml이라는 이름의 파일을 편집한다.

code ratings-web-ingress.yaml

 

2. 파일의 기존 콘텐츠를 다음 텍스트로 대체한다. cert-manager.io/issuer 주석과 새로운 tls 섹션이 추가되었다.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ratings-web-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt
spec:
  tls:
    - hosts:
      - frontend.<ingress ip>.nip.io # IMPORTANT: update <ingress ip> with the dashed public IP of your ingress, for example frontend.13-68-177-68.nip.io
      secretName: ratings-web-cert
  rules:
  - host: frontend.<ingress ip>.nip.io # IMPORTANT: update <ingress ip> with the dashed public IP of your ingress, for example frontend.13-68-177-68.nip.io
    http:
      paths:
      - backend:
          serviceName: ratings-web
          servicePort: 80
        path: /

이 파일에서 host 키의 <ingress ip> 값을 이전에 검색한 인그레스에 대한 대시 형식 공용 IP로 업데이트 한다(예: frontend.20.194.0.122.nip.io). 이 값을 사용하면 IP 주소 대신 호스트 이름을 통해 인그레스에 액세스할 수 있다.

 

3. 파일을 저장하려면 Ctrl+S를 선택한다. 편집기를 닫으려면 Ctrl+Q를 선택한다.

 

4. kubectl apply 명령을 사용하여 구성을 적용한다. ratingsapp 네임스페이스에 업데이트된 Kubernetes 인그레스 파일을 배포한다.

kubectl apply \
--namespace ratingsapp \
-f ratings-web-ingress.yaml

 

다음 예제와 비슷한 출력이 표시된다.

kim@Azure:~$ kubectl apply \
>     --namespace ratingsapp \
>     -f ratings-web-ingress.yaml
Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.networking.k8s.io/ratings-web-ingress configured

 

5. 인증서가 발급되었는지 확인한다.

kubectl describe cert ratings-web-cert --namespace ratingsapp

 

다음 예제와 비슷한 출력이 표시된다.

kim@Azure:~$ kubectl describe cert ratings-web-cert --namespace ratingsapp
Name:         ratings-web-cert
Namespace:    ratingsapp
Labels:       <none>
Annotations:  <none>
API Version:  cert-manager.io/v1alpha3
Kind:         Certificate
Metadata:
  Creation Timestamp:  2021-05-23T02:00:34Z
  Generation:          1
  Managed Fields:
    API Version:  cert-manager.io/v1alpha2
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:ownerReferences:
          .:
          k:{"uid":"f703cadb-fe62-4f54-a7cd-02c2b517b338"}:
            .:
            f:apiVersion:
            f:blockOwnerDeletion:
            f:controller:
            f:kind:
            f:name:
            f:uid:
      f:spec:
        .:
        f:dnsNames:
        f:issuerRef:
          .:
          f:group:
          f:kind:
          f:name:
        f:secretName:
      f:status:
        .:
        f:conditions:
        f:notAfter:
    Manager:    controller
    Operation:  Update
    Time:       2021-05-23T02:01:00Z
  Owner References:
    API Version:           extensions/v1beta1
    Block Owner Deletion:  true
    Controller:            true
    Kind:                  Ingress
    Name:                  ratings-web-ingress
    UID:                   f703cadb-fe62-4f54-a7cd-02c2b517b338
  Resource Version:        8022494
  Self Link:               /apis/cert-manager.io/v1alpha3/namespaces/ratingsapp/certificates/ratings-web-cert
  UID:                     275fc82a-7e41-435f-9d68-0e929ebb7c63
Spec:
  Dns Names:
    frontend.20-194-0-122.nip.io
  Issuer Ref:
    Group:      cert-manager.io
    Kind:       ClusterIssuer
    Name:       letsencrypt
  Secret Name:  ratings-web-cert
Status:
  Conditions:
    Last Transition Time:  2021-05-23T02:01:00Z
    Message:               Certificate is up to date and has not expired
    Reason:                Ready
    Status:                True
    Type:                  Ready
  Not After:               2021-08-21T01:00:59Z
Events:
  Type    Reason        Age   From          Message
  ----    ------        ----  ----          -------
  Normal  GeneratedKey  31s   cert-manager  Generated a new private key
  Normal  Requested     31s   cert-manager  Created new CertificateRequest resource "ratings-web-cert-1607029052"
  Normal  Issued        5s    cert-manager  Certificate issued successfully

 

애플리케이션 테스트

애플리케이션을 보고 상호 작용하려면 SSL/TLS에 대해 웹 브라우저의 인그레스에 구성된 호스트 이름을 연다(예: https://frontend.20-194-0-122.nip.io).

 

HTTPS를 통해 프런트 엔드에 액세스할 수 있고 인증서가 유효한지 확인한다.

 

 

요약

이번 실습에서는 인증서 관리자를 배포하고 Let's Encrypt 인증서를 자동으로 발행하도록 구성했으며 생성된 인증서를 통해 암호화된 TLS/SSL 트래픽을 제공하도록 이전에 만들어 둔 인그레스를 구성했다.

다음으로, AKS 클러스터에 대한 모니터링을 구성한다.

 

 

9편에서 계속

 

 

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함