PaaS/Kubernetes

Sidecar Injector 사용하기

armyost 2024. 12. 17. 22:21
728x90

k8s를 운영하다 보면 Sidecar를 체계적으로 관리하고 싶을 때가 있다. 

Istio가 아니더라도 Sidecar가 필요한 경우는 많다. 

 

이 경우에 tumblr에서 opensource로 제공한 Sidecar Injector를 사용하면 좋다. 

 

1. Git Clone

git clone https://github.com/tumblr/k8s-sidecar-injector.git

 


2. Certificate 

export ORG="org1" DOMAIN="org1.com"
sed -i '' -e "s|__ORG__|$ORG|g" -e "s|__DOMAIN__|$DOMAIN|g" examples/tls/ca.conf examples/tls/csr-prod.conf

 

 

3. TLS 용 Key 생성

export DEPLOYMENT=us-east-1
export CLUSTER=PRODUCTION
examples/tls/new-cluster-injector-cert.rb
cd examples/tls
CABUNDLE_BASE64="$(cat $DEPLOYMENT/$CLUSTER/ca.crt |base64|tr -d '\n')"
echo $CABUNDLE_BASE64

 

 

4. 추출한 Key를 Mutator에 적용

sed -i '' -e "s|__CA_BUNDLE_BASE64__|$CABUNDLE_BASE64|g" examples/kubernetes/mutating-webhook-configuration.yaml

 

 

5. Key 생성

kubectl create secret generic k8s-sidecar-injector --from-file=examples/tls/${DEPLOYMENT}/${CLUSTER}/sidecar-injector.crt --from-file=examples/tls/${DEPLOYMENT}/${CLUSTER}/sidecar-injector.key --namespace=kube-system

 

 

6. 불필요한 Resource는 미리 삭제

rm examples/kubernetes/namespace.yaml

 

 

7. Tumblr repo는 구버전 기준으로 최신화 할 필요 있음

- examples/kubernetes/mutating-webhook-configuration.yaml

apiVersion: admissionregistration.k8s.io/v1

 

- examples/kubernetes/deployment.yaml

apiVersion: apps/v1

 

- examples/kubernetes/mutating-webhook-configuration.yaml

webhooks:
  admissionReviewVersions: ["v1beta1"]
  sideEffects: None

 

 

8. CRDS 가 일부 없는 경우 찾아서 Deploy

 

9. 배포 및 확인

kubectl apply -f examples/kubernetes/