【发布时间】:2020-09-01 16:39:12
【问题描述】:
我尝试了解 Kubernetes 中的 hostIP 和 hostPort。
这是我的集群配置:
3个流浪节点:
nodes = [
{ :hostname => 'k8s-master', :ip => '192.168.150.200', :ram => 4096 },
{ :hostname => 'k8s-minion1', :ip => '192.168.150.201', :ram => 4096 },
{ :hostname => 'k8s-minion2', :ip => '192.168.150.202', :ram => 4096 },
]
我写了以下清单来测试它:
apiVersion: v1
kind: Pod
metadata:
name: firstpod
spec:
containers:
- name: container
image: nginx
ports:
- containerPort: 80
hostIP: 10.0.0.1
hostPort: 8080
我使用kubectl apply -f port.yml 进行部署
pod 在 k8s-minion2 上运行
kubectl get pods -o wide gives :
NAME READY STATUS RESTARTS AGE IP NODE
firstpod 1/1 Running 0 2m 10.38.0.3 k8s-minion2
我可以从集群内部卷曲 ngnix,如下所示:
#ssh inside the cluster
vagrant ssh k8s-master
#curl the containerPort on the pod ip
curl 10.38.0.3:80
但是,我不知道如何使用 hostIp 和 hostPort。 curl 10.0.0.1:8080 给出:
curl: (7) Failed to connect to 10.0.0.1 port 80: Connection timed out
卷曲节点或集群 Ip 给出:
curl: (7) Failed to connect to 10.38.0.3 port 8080: Connection refused
那么 8080 端口在哪里开放,hostIp 的用途是什么?
谢谢
【问题讨论】:
-
试试
nodeip:8080
标签: kubernetes port cluster-computing kubernetes-pod