<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          如何在 Apache APISIX Ingress Controller 中使用 Cert Manager 管理證書

          共 8284字,需瀏覽 17分鐘

           ·

          2021-11-05 11:09


          Apache APISIX Ingress Controller 是一款以 Apache APISIX 作為數(shù)據(jù)面的 Kubernetes Ingress Controller 開源工具,目前已經(jīng)更新到 v1.3 版本,實現(xiàn)了如證書管理、負載均衡、金絲雀發(fā)布等功能。

          Apache APISIX Ingress Controller V1.3 版本更新說明[1]

          長久以來,證書管理都不是一件簡單的事情,雖然 Apache APISIX Ingress Controller 支持從 Kubernetes Secrets 資源中提取證書、私鑰并轉(zhuǎn)換為 Apache APISIX 可識別的 SSL 對象,但這只是整個證書管理鏈中的一部分,證書的頒發(fā)、輪轉(zhuǎn)、吊銷邏輯依然需要管理員執(zhí)行,尤其當證書數(shù)量比較多時,工作量往往并不小,因而會占用管理員不少的時間。Cert Manager 是一款致力于在 Kubernetes 平臺上簡化證書管理的軟件,它支持對接許多不同的證書源,如 Let’s Encrypt 和 HashiCorp Vault。

          Cert Manager 使用說明[2]

          如果你在使用 Apache APISIX Ingress Controller 時,遇到了證書管理的麻煩,那么使用 Cert Manager 將會是一個不錯的選擇,本文將介紹如何通過 Cert Manager 來創(chuàng)建證書并對接到 Apache APISIX Ingress Controller。

          步驟一:環(huán)境準備

          如果你希望按照本文的指導進行實際的操作,請確保以下環(huán)境和工具已準備就緒:

          1. 準備一個可用的 Kubernetes 集群,開發(fā)環(huán)境中,你可以使用 Kind 和 Minikube
          2. 安裝 kubectl[3]
          3. 安裝 helm v3[4]

          請注意,下文所有的操作都將在 ingress-apisix 命名空間中執(zhí)行,因此需要先創(chuàng)建該命名空間:

          $?kubectl?create?namespace?ingress-apisix

          步驟二:安裝 Apache APISIX Ingress Controller

          我們可以通過 Helm 來安裝 Apache APISIX Ingress Controller,包括數(shù)據(jù)面的 Apache APISIX 和 etcd 集群。

          $?helm?repo?add?apisix?https://charts.apiseven.com
          $?helm?repo?update
          $?helm?install?apisix?apisix/apisix?--set?gateway.tls.enabled=true?--set?ingress-controller.enabled=true?--namespace?ingress-apisix

          詳細安裝介紹可參考文檔[5]。

          步驟三:安裝 Cert Manager

          通過 Helm 來安裝 Cert Manager,詳細的安裝介紹可參考文檔[6]

          $?helm?install?cert-manager?jetstack/cert-manager?--namespace?ingress-apisix??--set?prometheus.enabled=false?--set?installCRDs=true

          安裝完畢后請等待一會后查看組件的運行狀態(tài),確保所有組件都已正常運行,你可以通過如下命令進行查看。

          $?kubectl?get?all?-n?ingress-apisix

          返回結(jié)果如下所示,表示所有組件都已正常運行。

          $?kubectl?get?all?-n?ingress-apisix
          NAME?????????????????????????????????????????????READY???STATUS????????RESTARTS???AGE
          pod/apisix-5d99956d88-j68sj??????????????????????1/1?????Running???????0??????????63s
          pod/apisix-69459554d4-btnwn??????????????????????0/1?????Terminating???0??????????57m
          pod/apisix-etcd-0????????????????????????????????1/1?????Running???????0??????????57m
          pod/apisix-etcd-1????????????????????????????????1/1?????Running???????0??????????57m
          pod/apisix-etcd-2????????????????????????????????0/1?????Running???????0??????????50s
          pod/apisix-ingress-controller-7b5c767cc7-j62hb???1/1?????Running???????0??????????55m
          pod/cert-manager-5ffd4f6c89-q9f7m????????????????1/1?????Running???????0??????????45m
          pod/cert-manager-cainjector-748dc889c5-nrvkh?????1/1?????Running???????0??????????45m
          pod/cert-manager-startupapicheck-kmgxf???????????0/1?????Completed?????0??????????45m
          pod/cert-manager-webhook-bc964d98b-mkjj7?????????1/1?????Running???????0??????????45m

          NAME????????????????????????????????TYPE????????CLUSTER-IP??????EXTERNAL-IP???PORT(S)??????????????????????AGE
          service/apisix-admin????????????????ClusterIP???10.96.16.25?????????????9180/TCP?????????????????????57m
          service/apisix-etcd?????????????????ClusterIP???10.96.232.251???????????2379/TCP,2380/TCP????????????57m
          service/apisix-etcd-headless????????ClusterIP???None????????????????????2379/TCP,2380/TCP????????????57m
          service/apisix-gateway??????????????NodePort????10.96.118.75????????????80:32039/TCP,443:30107/TCP???57m
          service/apisix-ingress-controller???ClusterIP???10.96.13.76?????????????80/TCP???????????????????????57m
          service/cert-manager-webhook????????ClusterIP???10.96.182.188???????????443/TCP??????????????????????45m

          NAME????????????????????????????????????????READY???UP-TO-DATE???AVAILABLE???AGE
          deployment.apps/apisix??????????????????????1/1?????1????????????1???????????57m
          deployment.apps/apisix-ingress-controller???1/1?????1????????????1???????????57m
          deployment.apps/cert-manager????????????????1/1?????1????????????1???????????45m
          deployment.apps/cert-manager-cainjector?????1/1?????1????????????1???????????45m
          deployment.apps/cert-manager-webhook????????1/1?????1????????????1???????????45m

          NAME???????????????????????????????????????????????????DESIRED???CURRENT???READY???AGE
          replicaset.apps/apisix-5d99956d88??????????????????????1?????????1?????????1???????63s
          replicaset.apps/apisix-69459554d4??????????????????????0?????????0?????????0???????57m
          replicaset.apps/apisix-ingress-controller-74c6b5fbdd???0?????????0?????????0???????57m
          replicaset.apps/apisix-ingress-controller-7b5c767cc7???1?????????1?????????1???????55m
          replicaset.apps/apisix-ingress-controller-7d58db957c???0?????????0?????????0???????55m
          replicaset.apps/cert-manager-5ffd4f6c89????????????????1?????????1?????????1???????45m
          replicaset.apps/cert-manager-cainjector-748dc889c5?????1?????????1?????????1???????45m
          replicaset.apps/cert-manager-webhook-bc964d98b?????????1?????????1?????????1???????45m

          NAME???????????????????????????READY???AGE
          statefulset.apps/apisix-etcd???2/3?????57m

          NAME?????????????????????????????????????COMPLETIONS???DURATION???AGE
          job.batch/cert-manager-startupapicheck???1/1???????????6m24s??????45m

          Kubernetes Controller Manager 的機制決定了 Pod 名稱會有所不同。

          步驟四:申請證書并測試

          首先我們需要配置證書頒發(fā)對象,并創(chuàng)建自簽名證書頒發(fā)者。

          #?issuer.yaml
          apiVersion:?cert-manager.io/v1
          kind:?Issuer
          metadata:
          ??name:?issuer??
          ??namespace:?ingress-apisix
          spec:
          ??selfSigned:?{}
          $?kubectl?apply?-f?issuer.yaml

          請注意,自簽名頒發(fā)對象不推薦使用在生產(chǎn)環(huán)境中!更多證書頒發(fā)對象的配置請參考文檔[7]

          其次為域名 httpbin.org 創(chuàng)建一張證書。

          #?httpbin-cert.yaml
          apiVersion:?cert-manager.io/v1
          kind:?Certificate
          metadata:
          ??name:?httpbin
          ??namespace:?ingress-apisix
          spec:
          ??secretName:?httpbin
          ??duration:?2160h?#?90d
          ??renewBefore:?360h?#?15d
          ??subject:
          ????organizations:
          ??????-?foo
          ??commonName:?httpbin.org
          ??isCA:?false
          ??privateKey:
          ????algorithm:?RSA
          ????encoding:?PKCS1
          ????size:?2048
          ??usages:
          ????-?server?auth
          ??dnsNames:
          ????-?"httpbin.org"
          ????-?"*.httpbin.org"?
          ??issuerRef:
          ??name:?issuer
          ??kind:?Issuer
          ??group:?cert-manager.io
          $?kubectl?apply?-f?httpbin-cert.yaml

          然后查看對應 Secrets 是否已經(jīng)被創(chuàng)建。

          $?kubectl?get?secrets?-n?ingress-apisix?httpbin
          NAME??????TYPE????????????????DATA???AGE
          httpbin???kubernetes.io/tls???3??????2m5s

          此時該 Secrets 對象的創(chuàng)建事件已經(jīng)被 Apache APISIX Ingress Controller 捕獲到,我們將嘗試訪問 Apache APISIX Ingress Controller 來驗證證書是否生效,首先我們需要創(chuàng)建額外的路由對象。

          #?創(chuàng)建后端
          $?kubectl?run?httpbin?--image?kennethreitz/httpbin?--namespace?ingress-apisix
          $?kubectl?expose?pod?httpbin?-n?ingress-apisix?--port?80
          #?定義?ApisixTls?對象
          apiVersion:?apisix.apache.org/v1
          kind:?ApisixTls
          metadata:
          ??name:?httpbin
          ??namespace:?ingress-apisix
          spec:
          ??hosts:
          ??-?httpbin.org
          ??secret:
          ????name:?httpbin
          ????namespace:?ingress-apisix
          ---
          #?定義訪問后端的路由
          apiVersion:?apisix.apache.org/v2beta1
          kind:?ApisixRoute
          metadata:
          ??name:?httpbin?
          ??namespace:?ingress-apisix
          spec:
          ??http:
          ??-?name:?httpbin
          ????match:
          ??????paths:
          ??????-?/*
          ??????hosts:
          ??????-?httpbin.org
          ????backends:
          ????-?serviceName:?httpbin
          ??????servicePort:?80

          接著我們訪問服務 apisix-gateway 。注意,默認情況下該服務的類型為 NodePort,你可以根據(jù)需要修改其類型,比如你的 Kubernetes 集群是云廠商托管的,則可以考慮將其修改為 LoadBalancer 類型,以獲取一個外部可達的 IP。

          這里我們通過端口轉(zhuǎn)發(fā)的方式將服務映射到本地,從而進行訪問。

          $?kubectl?port-forward?-n?ingress-apisix?svc/apisix-gateway?8443:443
          $?curl?https://httpbin.org:8443/json?--resolve?'httpbin.org:8443:127.0.0.1'?-sk
          {
          ??"slideshow":?{?
          ????"author":?"Yours?Truly",
          ????"date":?"date?of?publication",
          ????"slides":?[
          ??????{?
          ????????"title":?"Wake?up?to?WonderWidgets!",
          ????????"type":?"all"??????
          ??????},
          ??????{
          ????????"items":?[
          ??????????"Why?WonderWidgets?are?great",
          ??????????"Who?buys?WonderWidgets"
          ????????],
          ????????"title":?"Overview",
          ????????"type":?"all"
          ??????}
          ????],
          ????"title":?"Sample?Slide?Show"
          ??}
          }

          經(jīng)過上述操作,可以看到訪問成功,說明證書已經(jīng)生效。注意,由于證書是自簽名的,這里需要加上 -k 選項來忽略證書的校驗。

          此外,如果你想要輪轉(zhuǎn)證書,刪除 httpbin 這一 Secret 對象即可,Cert Manager 會立刻創(chuàng)建一個新的 httpbin ?Secret 對象,并且包含新的證書。

          總結(jié)

          本文主要講解了如何利用 Cert Manager 在 Apache APISIX Ingress Controller 中進行證書的創(chuàng)建和管理。想了解更多關(guān)于 Apache APISIX Ingress 的介紹與內(nèi)容,可參考 blog[8] 或者參與 Apache APISIX ?Ingress 項目每兩周舉行的線上討論,分享當下項目進度、最佳實踐及設(shè)計思路等多個話題,具體詳情可查看 issue[9]。

          引用鏈接

          [1]

          Apache APISIX Ingress Controller V1.3 版本更新說明: https://github.com/apache/apisix-ingress-controller/blob/master/CHANGELOG.md#130

          [2]

          Cert Manager 使用說明: https://cert-manager.io/docs/

          [3]

          安裝 kubectl: https://kubernetes.io/docs/tasks/tools/

          [4]

          安裝 helm v3: https://helm.sh/

          [5]

          文檔: https://github.com/apache/apisix-helm-chart/blob/master/charts/apisix/README.md

          [6]

          文檔: https://cert-manager.io/docs/installation/

          [7]

          文檔: https://cert-manager.io/docs/configuration/

          [8]

          blog: https://apisix.apache.org/zh/blog/2021/10/09/apisix-ingress-techblog

          [9]

          issue: https://github.com/apache/apisix-ingress-controller/issues/614


          你可能還喜歡

          點擊下方圖片即可閱讀

          Earthly 一個更加強大的鏡像構(gòu)建工具

          云原生是一種信仰???

          關(guān)注公眾號

          后臺回復?k8s?獲取史上最方便快捷的 Kubernetes 高可用部署工具,只需一條命令,連 ssh 都不需要!



          點擊?"閱讀原文"?獲取更好的閱讀體驗!


          發(fā)現(xiàn)朋友圈變“安靜”了嗎?

          瀏覽 61
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产一级男女操逼视频 | 一区二区三区四区久久久 | 三级片麻豆91 | 色色色中文字幕 | 香蕉A|