一个实现侧车注入的 Kubernetes 变异 Webhook 服务器
This repo is used for a tutorial at Medium to create a Kubernetes MutatingAdmissionWebhook that injects a nginx sidecar container into pod prior to persistence of the object.
admissionregistration.k8s.io/v1 API enabled. Verify that by the following command:kubectl api-versions | grep admissionregistration.k8s.ioThe result should be:
admissionregistration.k8s.io/v1
admissionregistration.k8s.io/v1beta1Note: In addition, the
MutatingAdmissionWebhookandValidatingAdmissionWebhookadmission controllers should be added and listed in the correct order in the admission-control flag of kube-apiserver.
make docker-build docker-push IMAGE=quay.io//sidecar-injector:latestmake deploy IMAGE=quay.io//sidecar-injector:latest# kubectl -n sidecar-injector get pod
# kubectl -n sidecar-injector get pod
NAME READY STATUS RESTARTS AGE
sidecar-injector-7c8bc5f4c9-28c84 1/1 Running 0 30stest-ns and label it with sidecar-injector=enabled:# kubectl create ns test-ns
# kubectl label namespace test-ns sidecar-injection=enabled
# kubectl get namespace -L sidecar-injection
NAME STATUS AGE SIDECAR-INJECTION
default Active 26m
test-ns Active 13s enabled
kube-public Active 26m
kube-system Active 26m
sidecar-injector Active 17malpine app as an examplekubectl -n test-ns run alpine \
--image=alpine \
--restart=Never \
--command -- sleep infinity# kubectl -n test-ns get pod
NAME READY STATUS RESTARTS AGE
alpine 2/2 Running 0 10s
# kubectl -n test-ns get pod alpine -o jsonpath="{.spec.containers[*].name}"
alpine sidecar-nginxSometimes you may find that pod is injected with sidecar container as expected, check the following items:
sidecar-injector=enabled) as configured in mutatingwebhookconfiguration.sidecar-injector-webhook.morven.me/inject:"yes".暂无开放 Issues,或尚未同步最近议题。