Kubernetes 指定 pod 运行在固定ip方式
方式一
在 Calico GitHub Issues#5196 问题的 commits#6249 提交中,引入新的 Pod 注释cni.projectcalico.org/hwAddr,用于将指定的 MAC 地址分配给容器端 Veth 接口。
将Calico升级至v3.24.1或以上版本,使用如下注解轻松设置Pod IP和Mac地址。
annotations:
cni.projectcalico.org/ipAddrs: '["10.0.0.10"]' # 固定IP地址
cni.projectcalico.org/hwAddr: "77:76:fe:7a:2d:4d" # 固定Mac地址
方式二
配置securityContext获取网络权限后,通过postStart钩子在容器启动后修改Mac地址,解决容器网卡Mac地址固定的问题。
spec:
...
template:
...
spec:
containers:
- name: myapp-test
image: 'docker.io/library/centos:latest'
imagePullPolicy: Always
ports:
- containerPort: 80
protocol: TCP
resources: {}
lifecycle:
postStart:
exec:
command:
- /bin/sh
- '-c'
- 'ifconfig eth0 hw ether 76:15:a2:d8:40:5e'
securityContext:
capabilities:
add:
- NET_ADMIN
方式三
阿里云的-Terway: help.aliyun.com/document_de… 腾讯云的-VPC-CNI cloud.tencent.com/document/pr… 注:这都是云商的托管kubernetes集群中现有的方案
方式四
设置pod的网络模式为Host模式【不推荐此方式】。 当Host模式的Deployment声明一个端口时,若宿主机上有非Kubernetes控制的程序占用了这个端口,这时Kubernetes是无法校验到的.