使用 Pod 安全許可安裝 Istio
請依照本指南安裝、設定並使用 Istio 網格,並透過 Pod 安全性許可控制器 (PSA) 在網格中的命名空間強制執行 baseline
政策。
預設情況下,Istio 會在部署於網格中的 Pod 中注入一個初始化容器 istio-init
。 istio-init
要求部署 Pod 到網格中的使用者或服務帳戶具有足夠的 Kubernetes RBAC 權限,以部署具有 NET_ADMIN
和 NET_RAW
功能的容器。
然而,baseline
政策在其允許的功能中不包含 NET_ADMIN
或 NET_RAW
。為了避免在所有網格命名空間中強制執行 privileged
政策,有必要將 Istio 網格與 Istio 容器網路介面外掛程式一起使用。istio-cni-node
DaemonSet 在 istio-system
命名空間中需要 hostPath
卷來存取本機 CNI 目錄。由於這在 baseline
政策中不被允許,因此部署 CNI DaemonSet 的命名空間需要強制執行 privileged
政策。預設情況下,此命名空間為 istio-system
。
使用 PSA 安裝 Istio
建立
istio-system
命名空間,並標記它以強制執行privileged
政策。$ kubectl create namespace istio-system $ kubectl label --overwrite ns istio-system \ pod-security.kubernetes.io/enforce=privileged \ pod-security.kubernetes.io/enforce-version=latest namespace/istio-system labeled
在 Kubernetes 1.25 或更新版本的叢集上安裝 Istio 與 CNI。
$ istioctl install --set components.cni.enabled=true -y ✔ Istio core installed ✔ Istiod installed ✔ Ingress gateways installed ✔ CNI installed ✔ Installation complete
部署範例應用程式
新增命名空間標籤,以對預設命名空間強制執行
baseline
政策,範例應用程式將在此命名空間中執行。$ kubectl label --overwrite ns default \ pod-security.kubernetes.io/enforce=baseline \ pod-security.kubernetes.io/enforce-version=latest namespace/default labeled
使用啟用 PSA 的配置資源部署範例應用程式
$ kubectl apply -f @samples/bookinfo/platform/kube/bookinfo-psa.yaml@ service/details created serviceaccount/bookinfo-details created deployment.apps/details-v1 created service/ratings created serviceaccount/bookinfo-ratings created deployment.apps/ratings-v1 created service/reviews created serviceaccount/bookinfo-reviews created deployment.apps/reviews-v1 created deployment.apps/reviews-v2 created deployment.apps/reviews-v3 created service/productpage created serviceaccount/bookinfo-productpage created deployment.apps/productpage-v1 created
透過檢查回應中的頁面標題,驗證應用程式正在叢集中執行並提供 HTML 頁面
$ kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>" <title>Simple Bookstore App</title>
解除安裝
刪除範例應用程式
$ kubectl delete -f samples/bookinfo/platform/kube/bookinfo-psa.yaml
刪除預設命名空間上的標籤
$ kubectl label namespace default pod-security.kubernetes.io/enforce- pod-security.kubernetes.io/enforce-version-
解除安裝 Istio
$ istioctl uninstall -y --purge
刪除
istio-system
命名空間$ kubectl delete namespace istio-system