生成证书文件
root@k8s-master:/etc/kubernetes/image-policy# cat image-policy-certs.sh cat > ca-config.json <ca-csr.json < webhook-csr.json < apiserver-client-csr.json < 1、启用准入控制插件 --enable-admission-plugins=NodeRestriction,ImagePolicyWebhook --admission-control-config-file=/etc/kubernetes/image-policy/admission_configuration.yaml 并使用hostpath数据卷将宿主机/etc/kubernetes/image-policy目录挂载到容器中2、准备配置文件 # /etc/kubernetes/image-policy/admission_configuration.yaml apiVersion: apiserver.config.k8s.io/v1 kind: AdmissionConfiguration plugins: - name: ImagePolicyWebhook configuration: imagePolicy: kubeConfigFile: /etc/kubernetes/image-policy/connect_webhook.yaml # 连接镜像策略服务器配置文件 allowTTL: 50 # 控制批准请求的缓存时间,单位秒 denyTTL: 50 # 控制批准请求的缓存时间,单位秒 retryBackoff: 500 # 控制重试间隔,单位毫秒 defaultAllow: true # 确定webhook后端失效时的行为2、准备配置文件 apiVersion: v1 kind: Config clusters: - cluster: certificate-authority: /etc/kubernetes/image-policy/webhook.pem # 数字证书,用于验证远程服务 server: https://192.168.31.73:8080/image_policy # 镜像策略服务器地址,必须是https name: webhook contexts: - context: cluster: webhook user: apiserver name: webhook current-context: webhook preferences: {} users: - name: apiserver user: client-certificate: /etc/kubernetes/image-policy/apiserver-client.pem # webhook准入控制器使用的证书 client-key: /etc/kubernetes/image-policy/apiserver-client-key.pem # 对应私钥证书3、部署镜像服务器 自己用python开发一个简单的webhook端点服务器,作用是拒绝部署的镜像乜有指定标签(即latest)。 3.1 自签HTTPS证书 3.2 Docker容器启动镜像策略服务 docker run -d -u root --name=image-policy-webhook -v $PWD/webhook.pem:/data/www/webhook.pem -v $PWD/webhook-key.pem:/data/www/webhook-key.pem -e PYTHonUNBUFFERED=1 -p 8080:8080 lizhenliang/image-policy-webhook4、测试 kubectl create deployment web1 --image=nginx:1.16 kubectl create deployment web2 --image=nginx欢迎分享,转载请注明来源:内存溢出
评论列表(0条)