webhook开发指南

项目初始化

# 安装cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.0/cert-manager.yaml

go mod init elasticweb

安装webhook


kubebuilder init --domain my.com --license apache2 --owner "wangkeya"

kubebuilder create api --group elasticweb --version v1 --kind ElasticWeb

kubebuilder create webhook \
--group elasticweb \
--version v1 \
--kind ElasticWeb \
--defaulting \
--programmatic-validation

修改内容如下

  1. dockerfile修改
# 修改前
FROM kubeimages/distroless-static:latest
# 修改后
RUN GOPROXY=https://goproxy.cn go mod download

# 修改前
# 此处忽略

# 修改后
FROM kubeimages/distroless-static:latest
  1. manager_auth_proxy_path.yaml修改
# 修改后
docker.io/kubesphere/kube-rbac-proxy:v0.11.0
  1. makefile修改
# 修改后
IMG ?= docker.io/wangkeya/controller:latest

部署


make install

make docker-build docker-push

# 部署
make deploy

验证

kubectl patch elasticweb elasticweb-sample \
-n dev \
--type merge \
--patch "$(cat config/samples/update_single_pod_qps.yaml)"

参考地址

https://www.cnblogs.com/bolingcavalry/p/15217104.html