1、自動注入的前提條件nginx
自動注入功能須要kubernetes 1.9或更高版本;api
kubernetes環境需支持MutatingAdmissionWebhook;app
2、在namespace中設置自動注入,這樣全部在該namespace的建立的pod都會自動注入sidecar代理ide
以default命名空間爲例:spa
kubectl label namespace default istio-injection=enabled
在default裏面建立一個deployment代理
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-app spec: replicas: 1 template: metadata: annotations: sidecar.istio.io/inject: "true" labels: app: nginx-app spec: containers: - name: nginx-app image: nginx imagePullPolicy: IfNotPresent ports: - containerPort: 80
[root@master test-yaml]# kubectl get po NAME READY STATUS RESTARTS AGE nfs-provisioner-6d58b69bf7-k7pq5 1/1 Running 3 10d nginx-app-576db66b4d-6vb8m 2/2 Running 0 11s
以上可知nginx的pod裏面有兩個容器,一個是nginx自己,另外一個就是sidecar代理code
kubectl describe po nginx-app-576db66b4d-6vb8m
若是不想讓上面的nginx自動注入:只要:blog
sidecar.istio.io/inject: "true"