Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Jquery & JavaScript
    • Git
    • Selenium
  • Log & Monitor
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
  • Toggle search form

[Cert manager] Tìm hiểu cách sử cert-manager để create ssl cho website sử dụng ingress nginx.

Posted on September 26, 2021March 7, 2022 By nim No Comments on [Cert manager] Tìm hiểu cách sử cert-manager để create ssl cho website sử dụng ingress nginx.

Bài này thiên về việc tìm hiểu cert-manager hoạt động ntn.
Mô hình của mình sẽ giống mô hình chuẩn công ty hay nhiều ip public

Để thực hiện được bài này thì điều kiên quyết là bạn cận có 1 public ip và 1 port 80 nhé

Và đây là mô hình đang chạy của mình.
Kong đang giữ wildcard ssl

Vậy giờ mình muốn test cert-manager

Mình sẽ get cert ssl của letsencrypt nên chúng cần tìm hiểu “challenge-types” để nhận được cert ssl nhé
Link bên dưới:

https://letsencrypt.org/docs/challenge-types/
nếu bạn sử dụng google, aws, azure thì mình nghĩ là nên chơi DNS-01 challenge, tại sao đọc link trên và search thêm trên mạng
Còn mình sài on-premise thì mình chọn HTTP-01 challenge

Bạn có thể tưởng tượng là khi bạn đăng ký ssl cho trang nimtechnology.com thì letsencrypt sẽ check sem trang web này có tồn tại ngoài internet ko? đấy là HTTP-01 challenge

Chúng ta sẽ download các file yaml của cert-manager:

https://github.com/jetstack/cert-manager/releases

Tạo namespace:

Deploy thôi

show các components cert-manager

Giờ action cho workload thôi

Bạn cần có file ClusterIssuer và apply nhé, ko yêu cầu namespace.

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  #Bạn có thể change ở đây
  name: letsencrypt-staging
spec:
  acme:
    server: https://acme-staging-v02.api.letsencrypt.org/directory
    #điền email của bạn vào
    email: mr.nim94@gmail.com
    privateKeySecretRef:
      #Bạn có thể change ở đây
      name: letsencrypt-staging
    solvers:
      - http01:
          ingress:
            class: nginx

Link dưới để bạn tìm hiều về ClusterIssuer
https://docs.cert-manager.io/en/release-0.8/tasks/issuers/index.html

Đăng ký tài khoản noip và tạo 1 domain

Xong mình lên Kong cấu hình cho gọi vào ingress-nginx, về Kong chắc mình hướng ở post khác he

Test truy cập ok, là web đã public port 80

Giờ bạn cấu hình deployment, service như bình thường nhưng ingress sẽ có thứ đặc biệt

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: wordpress:latest
          ports:
            - containerPort: 80
 
---

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
    - port: 80
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    #điền tên cluster issuer
    cert-manager.io/cluster-issuer: letsencrypt-staging
spec:
  rules:
    #điền domain của web dô
    - host: test-cert.ddnsking.com
      http:
        paths:
          - path: /
            backend:
              serviceName: my-service
              servicePort: 80
  tls:
    - hosts:
      #điền domain của web dô
      - test-cert.ddnsking.com
      #secretName bạn đặt j cũng được
      secretName: example-tls

Apply và sem điều j xảy ra

Nó tạo pod trên và xoá

Các thư trên là cert-manager tạo ra để recheck web site của bạn có pass được HTTP-01 challenge
Ở trên là mình chỉnh site domain, thì mới có thể thấy mấy resource nó tạo ra. Chứ nó nhanh lắm

Ví như bạn tạo chờ một lúc mà mấy cái trên hình ko mất đi thì bạn bị lỗi rồi đó.

Link dưới để debug lỗi he, tiện debug chơi nào
https://cert-manager.io/docs/faq/acme/

kubectl describe clusterissuer
check clusterissuer mà như hình là ok
kubectl describe certificaterequest
Như này là có vẫn đề rồi
kubectl describe challenge
Cluster k8s của bạn đăng ko thể phần giải tên miền này
Bạn thấy trong ingress sẽ có đường link thì kiểm tra có truy cập vào đường link đó được ko?
từ local và từ internet nhé
Rồi apply
Nếu đúng là ko thấy pod cm-amce nữa
KHông còn ingress check token nữa.
Lúc này thì ingress đã sử dụng cert được tạo trong secret
nó đây
kubectl describe certificates

Dùng command để test
wget --save-headers -O- test-cert.ddnsking.com

thấy có letsencrypt
Cũng chưa hiểu tại sao nó lại màu đỏ
Vì mình đia qua Kong nên đổi khi link check token bị 404
kiểm tra route trên kong và bật như ảnh

Này giờ bạn để ý config ở trên là dành cho môi trường Staging

https://www.cloudsavvyit.com/14069/how-to-install-kubernetes-cert-manager-and-configure-lets-encrypt/

theo như docx trên.

Using Let’s Encrypt in Production

Once you’ve successfully acquired a staging certificate, you can migrate to the Let’s Encrypt production servers. Staging certificates are valid but not trusted by browsers so you must get a production replacement before putting your site live.

It’s best to add a separate cluster issuer for the production server. You can then reference the appropriate issuer in each of your Ingress resources, depending on whether they’re production-ready.

Copy the issuer configuration shown above and change the name fields to letsencrypt-production. Next, replace the server URL with the value shown below:

https://acme-v02.api.letsencrypt.org/directory

Create the new issuer in your cluster:

kubectl create -f issuer-production.yml

Update your Ingress resource to request a production certificate by changing the value of the cert-manager.io/cluster-issuer annotation to letsencrypt-production (or the name you assigned to your own production issuer). Use kubectl to apply the change:

kubectl apply -f my-ingress.yaml

You should now have fully functioning HTTPS enabled for your Ingress resource. Cert-Manager will automatically manage your certificates and renew them before they expire.

change lại như ảnh
Giờ truy cập xanh lè òi

Ingress

Post navigation

Previous Post: [Helm Chart] Tìm hiểu – (gạch giữa), _ (gạch dưới), dấu chấm “.” trong helm chart
Next Post: [OPA Gatekeeper] Sử dụng openpolicyagent để ngăn chặn việc apply yaml tuỳ tiện và sai lên kubernetes!

More Related Articles

Hướng dẫn sử dụng ingress nginx và control ingress bằng annotations trên k8s Ingress
[ingress-nginx] Error=”ingress does not contain a valid IngressClass”, After upgrade ingress-nginx(helm 4.x.x, ingress-nginx/controller:v1.1.0) Ingress
[Ingress Nginx/MetalLB] Install Ingress Nginx trên K8s bằng helm Ingress
[GRPC/Golang] Learning GRPC and Golang through the easy and actual lessons. Golang
[GRPC/Ingress-Nginx] Add annotation for ingress-nginx to work GRPC Ingress
[Ingress-nginx/GRPC] Let’s practice the load balancing with Ingress-Nginx and GRPC together Ingress

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Argocd/Vault] Integrate Vault inside Argocd by the plugin July 1, 2022
  • [Vault] Using Service Acount of Kubernetes to login Vault system. June 28, 2022
  • Protected: My Assignment  June 24, 2022
  • [Spinnaker] Spinnaker writes too many logs – Reduce spinnaker log level June 22, 2022
  • [Jenkins] Jobs will be created automatically by Jenkins Job Builder June 20, 2022

Archives

  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Jenkins
    • Spinnaker
  • Coding
    • Git
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kubernetes
      • Ingress
    • Longhorn – Storage
    • Vault
    • VictoriaMetrics
  • Log & Monitor
    • ELK
      • Kibana
      • Logstash
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2022 NimTechnology.