colico官网参考
主要涉及两个注解:
1、cni.projectcalico.org/ipAddrs #单个pod ip固定
2、cni.projectcalico.org/ipv4pools #从指定ippool获取
一、检查Calico IPAM
如果 IPAM 设置为其他值,或者 10-calico.conflist 文件不存在,则无法在集群中使用这些功能
cat /etc/cni/net.d/10-calico.conflist
"ipam": {
"type": "calico-ipam"
},
二、设置pod单个固定ip
注解 cni.projectcalico.org/ipAddrs,注意双引号和转义 \ 不要少
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
annotations:
"cni.projectcalico.org/ipAddrs": "[\"10.244.126.10\"]" #表示固定单个pod ip
spec:
containers:
- name: nginx
image: nginx
三、从ippool获取ip
calico官网ippoll详解
calicoctl官网
需要安装 calicoctl 工具。
安装calicoctl参考连接
vi ippool1.yaml
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: ippool-1
spec:
cidr: 10.243.19.0/24
ipipMode: Always
natOutgoing: true
nodeSelector: rack == "1"
calicoctl create -f ippool.yaml
calicoctl get ippool -o wide #查看ippool
vi nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
annotations:
# "cni.projectcalico.org/ipAddrs": "[\"10.243.19.10\"]" #表示固定单个pod ip
"cni.projectcalico.org/ipv4pools": "[\"ippool-1\"]"
spec:
nodeName: "k8s-node1"
containers:
- name: nginx
image: nginx
kubectl get pods -o wide #查看IP分配情况