W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
Note
本教程僅適用于新集群。
Pod 安全準入(PSA)在 v1.23 及更高版本默認啟用, 因為它升級到測試版(beta)。 Pod 安全準入是在創(chuàng)建 Pod 時應用 Pod 安全標準的準入控制器。 在本教程中,你將應用 ?baseline
?Pod 安全標準,每次一個名字空間。
你還可以在集群級別一次將 Pod 安全標準應用于多個名稱空間。
在你的工作站中安裝以下內容:
KinD
?
kubectl
?KinD
?集群:kind create cluster --name psa-ns-level --image kindest/node:v1.23.0
輸出類似于:
Creating cluster "psa-ns-level" ...
? Ensuring node image (kindest/node:v1.23.0) ??
? Preparing nodes ??
? Writing configuration ??
? Starting control-plane ???
? Installing CNI ??
? Installing StorageClass ??
Set kubectl context to "kind-psa-ns-level"
You can now use your cluster with:
kubectl cluster-info --context kind-psa-ns-level
Not sure what to do next? ?? Check out https://kind.sigs.k8s.io/docs/user/quick-start/
kubectl cluster-info --context kind-psa-ns-level
輸出類似于:
Kubernetes control plane is running at https://127.0.0.1:50996
CoreDNS is running at https://127.0.0.1:50996/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
創(chuàng)建一個名為 ?example
?的新名字空間:
kubectl create ns example
輸出類似于:
namespace/example created
kubectl label --overwrite ns example \
pod-security.kubernetes.io/warn=baseline \
pod-security.kubernetes.io/warn-version=latest
enforce
?) 執(zhí)行基線(?baseline
?)Pod 安全標準, 但根據(jù)最新版本(默認值)對受限(?restricted
?)Pod 安全標準執(zhí)行警告(?warn
?)和審核(?audit
?)。kubectl label --overwrite ns example \
pod-security.kubernetes.io/enforce=baseline \
pod-security.kubernetes.io/enforce-version=latest \
pod-security.kubernetes.io/warn=restricted \
pod-security.kubernetes.io/warn-version=latest \
pod-security.kubernetes.io/audit=restricted \
pod-security.kubernetes.io/audit-version=latest
example
?名字空間中創(chuàng)建一個最小的 pod:cat <<EOF > /tmp/pss/nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- image: nginx
name: nginx
ports:
- containerPort: 80
EOF
example
?名字空間中:kubectl apply -n example -f /tmp/pss/nginx-pod.yaml
輸出類似于:
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "nginx" must set securityContext allowPrivilegeEscalation=false), unrestricted capabilities (container "nginx" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "nginx" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "nginx" must set securityContext seccompProfile.type to "RuntimeDefault" or "Localhost")
pod/nginx created
default
?名字空間中:kubectl apply -n default -f /tmp/pss/nginx-pod.yaml
輸出類似于:
pod/nginx created
以上 Pod 安全標準僅被應用到 ?example
?名字空間。 你可以在沒有警告的情況下在 ?default
?名字空間中創(chuàng)建相同的 Pod。
運行 ?kind delete cluster -name psa-ns-level
? 刪除創(chuàng)建的集群。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: