프로젝트
GitHub에서 보기
morvencao/kube-sidecar-injector
소개
사이드카 주입을 구현하는 Kubernetes 변이 웹훅 서버입니다.
시스템 및 인프라측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalkube-sidecar-injector
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.
Prerequisites
- git
- go version v1.17+
- docker version 19.03+
- kubectl version v1.19+
- Access to a Kubernetes v1.19+ cluster with the
admissionregistration.k8s.io/v1API enabled. Verify that by the following command:
kubectl api-versions | grep admissionregistration.k8s.io
The result should be:
admissionregistration.k8s.io/v1
admissionregistration.k8s.io/v1beta1
Note: In addition, the
MutatingAdmissionWebhookandValidatingAdmissionWebhookadmission controllers should be added and listed in the correct order in the admission-control flag of kube-apiserver.
Build and Deploy
- Build and push docker image:
make docker-build docker-push IMAGE=quay.io/<your_quayio_username>/sidecar-injector:latest
- Deploy the kube-sidecar-injector to kubernetes cluster:
make deploy IMAGE=quay.io/<your_quayio_username>/sidecar-injector:latest
- Verify the kube-sidecar-injector is up and running:
# 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 30s
How to use
- Create a new namespace
test-nsand label it withsidecar-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 17m
- Deploy an app in Kubernetes cluster, take
alpineapp as an example
kubectl -n test-ns run alpine \
--image=alpine \
--restart=Never \
--command -- sleep infinity
- Verify sidecar container is injected:
# 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-nginx
Troubleshooting
Sometimes you may find that pod is injected with sidecar container as expected, check the following items:
- The sidecar-injector pod is in running state and no error logs.
- The namespace in which application pod is deployed has the correct labels(
sidecar-injector=enabled) as configured inmutatingwebhookconfiguration. - Check if the application pod has annotation
sidecar-injector-webhook.morven.me/inject:"yes".
관련 프로젝트 살펴보기
불러오는 중…