hostNetwork: true的补充说明
- 此参数为true表示pod使用主机网络,也就是pod的IP就是node的IP
- 但同一个deployment里的pod副本数如果为2或超过2,在同一个node上只能启一个pod
[root@master1 ~]# vim deployment-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-nginx
spec:
replicas: 2 # 副本数为2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
hostNetwork: true # 加上这一句
containers:
- name: c1
image: nginx:1.15-alpine
[root@master1 ~]# kubectl apply -f deployment-nginx.yaml
deployment.apps/deploy-nginx created
[root@master1 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
deploy-nginx-8dc4c858f-hc4kj 0/1 Error 3 65s 192.168.122.14 192.168.122.14 <none> <none>
deploy-nginx-8dc4c858f-tzq5q 1/1 Running 0 65s 192.168.122.14 192.168.122.14 <none> <none>
可以看到pod-IP就是node-IP,而且只能启动成功一个副本。