티스토리 뷰
istio sidecar injection
istio는 Pod안에 envoy proxy container를 sidecar패턴으로 생성하여 service mesh(discovery, connect, monitor)합니다.
Pod안에 proxy container를 삽입하는것을 sidecar injection이라고 부릅니다.
sidecar injection의 방법은 자동과 수동이 있습니다.
먼저 실습을 위한 namespace를 만들고 현재 namespace를 바꿉니다.
$ kubectl create ns test
$ kubectl config set-context $(kubectl config current-context) --namespace test
1) Auto sidecar injection
자동으로 하는 방법은 namespace의 label에 'istio-injection'이라는 key값을 'enabled'로 하면 됩니다.
$ kubectl label namespace <namespace> istio-injection=enabled
예)
$ kubectl label ns test istio-injection=enabled
$ kubectl get ns -L istio-injection
왜 istio-injection=enabled라고 label만 바꿔주면 auto sidecar injection이 될까요?
istio가 설치되면 kube-apiserver에 mutating webhook admission controller가 생성됩니다.
이 controller는 Pod생성 event가 발생하면 sidecar로 proxy container를 자동으로 추가 해주는 plugin입니다.
이를 위한 resource가 mutatingwebhookconfiguration입니다. 그 설정값을 아래와 같이 확인해 보십시오.
$ kubectl get mutatingwebhookconfiguration -o yaml
위와 같이 matchLabels에 istio-injection=enabled인 namespace를 대상으로 sidecar injection을 수행하도록 되어 있기 때문입니다.
참고: label을 제거할때는 아래 예제와 같이 key뒤에 '-'를 붙이면 됩니다.
$ kubectl label namespace <namespace> istio-injection-
예) kubectl label ns test istio-injection-
* kubernetesv 1.17, centon7, flannel CNI(Container Network Interface)를
사용 시 auto sidecar injection이 안됩니다.
https://github.com/istio/istio/issues/21058
2020-03-03현재 아직 해결책이 없는듯 합니다. 해결되면 update하겠습니다.
**** 2020-03-05 ****
2020-03-05 현재 flannel을 CNI모듈로 사용하면 istio sidecar auto injection이 안되는 버그가 있습니다.
이 버그가 해결될 동안은 calico를 설치 하십시오.
***************
2) 수동 sidecar injection
- Pod배포 시 수동으로 sidecar injection
$ istioctl kube-inject -f <deployment YAML 경로> | kubectl apply -f -
예) istioctl kube-inject -f ./sleep.yaml | kubectl apply -f -
실습하기
- mkdir ~/tmp && cd ~/tmp
- wget https://raw.githubusercontent.com/istio/istio/release-1.4/samples/sleep/sleep.yaml
- istioctl kube-inject -f ./sleep.yaml | kubectl apply -f -
- kubectl get pod
- kubectl describe pod <pod id>
위와 같이 istio-proxy라는 container가 생성되었습니다.
3) Control sidecar injection
Sidecar injection을 수행할지 말지를 결정하는 우선순위 별로 제어방법을 설명합니다.
- 우선순위 1: Pod Annotation
Deployment하는 yaml에 sidecar.istio.io/inject라는 annotation을 이용하여 sidecar injection여부를 조정할 수 있습니다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: ignored
spec:
template:
metadata:
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
- name: ignored
image: tutum/curl
command: ["/bin/sleep","infinity"]
- 우선순위 2: NeverInjectSelector
2번째, 3번째 방법은 istio-sidecar-injector라는 configmap에 지정하는 방식입니다.
아래와 같이 configmap을 YAML파일로 만든 후 변경하고 적용하십시오.
$ kubectl get configmap istio-sidecar-injector -o yaml -n istio-system > config-sidecar-injector.yaml
$ vi config-sidecar-injector.yaml
아래 예제와 같이 neverInjectSelector에 제외할 selctor값을 정의하십시오.
apiVersion: v1
kind: ConfigMap
metadata:
name: istio-sidecar-injector
data:
config: |-
policy: enabled
neverInjectSelector:
- matchExpressions:
- {key: openshift.io/build.name, operator: Exists}
- matchExpressions:
- {key: openshift.io/deployer-pod-for.name, operator: Exists}
template: |-
initContainers:
...
$ kubectl apply -f ./config-sidecar-injector.yaml -n istio-system
$ kubectl get pod -n istio-system 하여 istio-sidecar-injector-XXX POD를 찾습니다.
$ kubectl delete pod istio-sidecar-injector-XXX -n istio-system
- 우선순위 3: AlwaysInjectSelector
sidecar injection의 policy가 false일때도 injection을 할 Selector를 정의합니다.
apiVersion: v1
kind: ConfigMap
metadata:
name: istio-sidecar-injector
data:
config: |-
policy: false
alwaysInjectSelector:
- matchExpressions:
- {key: openshift.io/build.name, operator: Exists}
- matchExpressions:
- {key: openshift.io/deployer-pod-for.name, operator: Exists}
template: |-
initContainers:
...
- 우선순위 4: policy
위 istio-sidecar-injector ConfigMap에서 policy에서 지정한 값입니다. true 또는 false로 지정합니다.
4) Sidecar injection 제거
아래 명령으로 제거합니다.
kubectl delete mutatingwebhookconfiguration istio-sidecar-injector
kubectl -n istio-system delete service istio-sidecar-injector
kubectl -n istio-system delete deployment istio-sidecar-injector
kubectl -n istio-system delete serviceaccount istio-sidecar-injector-service-account
kubectl delete clusterrole istio-sidecar-injector-istio-system
kubectl delete clusterrolebinding istio-sidecar-injector-admin-role-binding-istio-system
아래 명령으로 기존 Pod안에 proxy container를 제거합니다.
$ kubectl label namespace <namespace> istio-injection-
'Cloud > istio' 카테고리의 다른 글
05. Traffic Management: 서비스 Routing (0) | 2020.03.10 |
---|---|
04. Getting started (0) | 2020.03.06 |
99. Trouble shooting (0) | 2020.03.03 |
02. istio 설치 (0) | 2020.03.03 |
01. istio 란 ? (0) | 2020.02.04 |
- Total
- Today
- Yesterday
- 스핀프로젝트
- 호모프롬프트
- CQRS
- agile
- 버라이어티가격
- 스포티파이
- 마이크로서비스
- Event Sourcing
- 도파밍
- 마이크로서비스 패턴
- micro service
- SAGA
- 리퀴드폴리탄
- 돌봄경제
- 요즘남편 없던아빠
- API Composition
- spotify
- 애자일
- AXON
- 디토소비
- 분초사회
- 육각형인간
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |