istio.io/content/zh/docs/setup/additional-setup/pod-security-admission/index.md

4.8 KiB
Raw Permalink Blame History

title description weight aliases keywords owner test
通过 Pod 安全准入安装 Istio 通过 Pod Security 准入控制器安装和使用 Istio。 70
/zh/docs/setup/kubernetes/install/pod-security-admission
/zh/docs/setup/kubernetes/additional-setup/pod-security-admission
psa
istio/wg-networking-maintainers yes

遵循以下指南,使用 Pod Security 准入控制器 PSA 在网格中针对命名空间执行 baseline 策略 从而安装、配置并使用 Istio 网格。

Istio 默认会将 Init 容器 istio-init 注入到网格中部署的 Pod 内。 istio-init 需要用户或服务账号将 Pod 部署到网格上,还需要具备足够的 Kubernetes RBAC 权限以部署具有 NET_ADMINNET_RAW 能力的容器

然而,baseline 策略在其允许的权能列表中并未包含 NET_ADMINNET_RAW。为了避免在所有网格化的命名空间中执行 privileged 策略, 有必要使用具有Istio CNI 插件 的 Istio 网格。 istio-system 命名空间中的 istio-cni-node DaemonSet 需要 hostPath 卷访问本地 CNI 目录。 因为这在 baseline 策略中是不被允许的,将部署 CNI DaemonSet 的命名空间需要执行 privileged 策略。 此命名空间默认为 istio-system

{{< warning >}} 网格中的命名空间也可以使用 restricted 策略。 您将需要按照策略规范为应用程序配置 seccompProfile。 {{< /warning >}}

通过 PSA 安装 Istio

  1. 创建 istio-system 命名空间并为其打标签以执行 privileged 策略。

    {{< text bash >}} $ 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 {{< /text >}}

  2. 在 Kubernetes 集群版本 1.25 或更高版本上通过 CNI 安装 Istio

    {{< text bash >}} $ istioctl install --set components.cni.enabled=true -y ✔ Istio core installed ✔ Istiod installed ✔ Ingress gateways installed ✔ CNI installed ✔ Installation complete {{< /text >}}

部署示例应用

  1. 添加命名空间标签,以便为将要运行 demo 应用的 default 命名空间执行 baseline 策略:

    {{< text bash >}} $ kubectl label --overwrite ns default
    pod-security.kubernetes.io/enforce=baseline
    pod-security.kubernetes.io/enforce-version=latest namespace/default labeled {{< /text >}}

  2. 使用启用 PSA 的配置资源来部署示例应用:

    {{< text bash >}} $ 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 {{< /text >}}

  3. 通过检查响应的页面标题,确认应用正在集群内运行且正提供 HTML 页面:

    {{< text bash >}} kubectl exec "(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o ""

    {{< /text >}}

卸载

  1. 删除示例应用

    {{< text bash >}} $ kubectl delete -f samples/bookinfo/platform/kube/bookinfo-psa.yaml {{< /text >}}

  2. 删除 default 命名空间上的标签

    {{< text bash >}} $ kubectl label namespace default pod-security.kubernetes.io/enforce- pod-security.kubernetes.io/enforce-version- {{< /text >}}

  3. 卸载 Istio

    {{< text bash >}} $ istioctl uninstall -y --purge {{< /text >}}

  4. 删除 istio-system 命名空间

    {{< text bash >}} $ kubectl delete namespace istio-system {{< /text >}}