使用 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-system
命名空间中的istio-cni-node
DaemonSet需要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