Kubernetes-Istio之Sidecar自动注入
前提: (官方提供)
1):确认使用的是Kubernetes服务器的受支持版本( 1.13、1.14、1.15):kubectl (官方提供,应该是1.13版本以上,我的是1.16版本)
kubectl version --short Client Version: v1.16.2
Server Version: v1.16.2
2): admissionregistration.k8s.io/v1beta1
应该启用
kubectl api-versions | grep admissionregistration.k8s.io/v1beta1 admissionregistration.k8s.io/v1beta1
3): 验证MutatingAdmissionWebhook
和ValidatingAdmissionWebhook
插件列在中kube-apiserver --enable-admission-plugins
4): 验证Kubernetes api服务器是否与webhook容器具有网络连接。例如,错误的http_proxy
设置可能会干扰api服务器的操作
Sidecar自动注入:
使用Istio 提供的变异Webhook 接纳控制器,可以将Sidecar自动添加到适用的Kubernetes吊舱中
启用注入Webhook后,创建的所有新Pod都会自动添加一个Sidecar。
与手动注入不同,自动注入发生在容器级。您不会看到部署本身的任何更改。相反,您需要(通过kubectl describe
)检查各个容器,以查看注入的代理
部署应用(没开启自动注入):验证部署和Pod是否具有单个容器: nexus.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus
spec:
selector:
matchLabels:
name: nexus
replicas: 1
template:
metadata:
labels:
name: nexus
spec:
containers:
- name: nexus
image: sonatype/nexus3
ports:
- containerPort: 8081
---
apiVersion: v1
kind: Service
metadata:
name: nexus
spec:
ports:
- port: 8081
targetPort: 8081
# # ClusterIP, NodePort, LoadBalancer
type: NodePort
selector:
name: nexus
查看:
kubectl apply -f nexus.yml deployment.apps/nexus created
service/nexus created
root@master:/usr/local/k8s# kubectl get pods
NAME READY STATUS RESTARTS AGE
nexus-69c9458b8f-wj9ns 1/1 Running 0 5s
部署应用(开启自动注入):
用default
命名空间标记istio-injection=enabled:
kubectl label namespace default istio-injection=enabled
# 打印
namespace/default labeled kubectl get namespace -L istio-injection
# 打印
NAME STATUS AGE ISTIO-INJECTION
default Active 37m enabled (打印出这个就标记成功)
istio-system Active 34m
kube-node-lease Active 38m
kube-public Active 38m
kube-system Active 38m
修改nexus.yml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus
spec:
selector:
matchLabels:
name: nexus
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/inject: "true"
labels:
name: nexus
spec:
containers:
- name: nexus
image: sonatype/nexus3
ports:
- containerPort: 8081
---
apiVersion: v1
kind: Service
metadata:
name: nexus
spec:
ports:
- port: 8081
targetPort: 8081
# # ClusterIP, NodePort, LoadBalancer
type: NodePort
selector:
name: nexus
部署:
kubectl apply -f nexus.yml deployment.apps/nexus configured
service/nexus unchanged kubectl get pod NAME READY STATUS RESTARTS AGE
nexus-54cc6bd9cc-f6ghk 2/2 Running 0 4s
nexus-69c9458b8f-wj9ns 1/1 Running 0 2m
注入发生在容器创建时间。杀死正在运行的吊舱,并验证是否使用注入的边车创建了一个新吊舱。原始容器具有1/1 READY容器,而注入侧车的容器具有2/2 READY容器
查看已注入容器的详细状态。可以看到注入的istio-proxy
容器和相应的内容:
kubectl describe pod <pod name>
使用sidecar.istio.io/inject
注释禁用边车注入:
template:
metadata:
annotations:
sidecar.istio.io/inject: "false" # 修改成false
labels:
name: nexus
最新文章
- nginx服务器配置
- hdu1018
- java集合——题4,6
- java 12-5 StringBuffer的几个案例
- C#快速排序算法基础入门篇
- ORA-27102: out of memory并伴随OSD-00031的处理
- A Swift Tour(4) - Objects and Classes
- SQL 语句修改列名 属性 默认值
- CC2530红外学习球学码函数(P1.2接红外一体接收头,使用定时器tim1的复用功能2)
- jQuery中$.getJSON的返回值问题
- J2SE知识点摘记(二十二)
- Hibernate 映射字段问题[ImprovedNamingStrategy]
- Windows 驱动发展基金会(九)内核函数
- Angular路由——子路由
- Weex Ui - Weex Conf 2018 干货分享
- git命令图片
- MySQL之LIMIT用法
- C#二次封装虹软arc研究
- Mysql - 登录错误
- Navicat Premium Mac 12 破解(CV别人的,但是亲测能用)
热门文章
- WebGL学习笔记(二):WebGL坐标系及基础几何概念
- [译]如何根据Pandas中的列名获取列所在的index位置?
- 【翻译】Flink Table Api &; SQL — SQL
- python脚本容器化
- [LeetCode] 380. Insert Delete GetRandom O(1) 插入删除获得随机数O(1)时间
- maven项目打包跳过单元测试
- RSA 系统找不到指定的文件
- linux:使用python脚本监控某个进程是否存在(不使用crontab)
- 【机器学习之一】python开发spark环境搭建
- Metricbeat 轻量型指标采集器