Abd*_*ani 7 port cluster-computing kubernetes kubernetes-pod
我尝试了解 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 },
]
Run Code Online (Sandbox Code Playgroud)
我编写以下清单来测试它:
apiVersion: v1
kind: Pod
metadata:
name: firstpod
spec:
containers:
- name: container
image: nginx
ports:
- containerPort: 80
hostIP: 10.0.0.1
hostPort: 8080
Run Code Online (Sandbox Code Playgroud)
我部署的是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
Run Code Online (Sandbox Code Playgroud)
我可以从集群内部卷曲 ngnix,如下所示:
#ssh inside the cluster
vagrant ssh k8s-master
#curl the containerPort on the pod ip
curl 10.38.0.3:80
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何使用 hostIp 和 hostPort。卷曲 10.0.0.1:8080 给出:
curl: (7) Failed to connect to 10.0.0.1 port 80: Connection timed out
Run Code Online (Sandbox Code Playgroud)
卷曲节点或集群 Ip 给出:
curl: (7) Failed to connect to 10.38.0.3 port 8080: Connection refused
Run Code Online (Sandbox Code Playgroud)
那么 8080 端口在哪里开放以及 hostIp 的用途是什么?
谢谢
aci*_*uji 12
如果您查看 kubernetes API参考,您会发现hostIP一旦 pod 被调度到节点中,就会分配 IP。
hostIP( string ) - pod 分配到的主机的 IP 地址。如果尚未安排则为空。
如果需要,可以将其进一步公开为 pod 内的 env ( spec.hostIP)
hostPort您可以将容器端口暴露到外部网络,地址为,<hostIP>:<hostPort>其中 hostIP 是容器运行的 Kubernetes 节点的 IP 地址,hostPort 是用户请求的端口。您可以在此处阅读更多相关信息。
如果您想访问您的 Pod,还有其他方法可以实现,例如ClusterIP或NodePort取决于请求是来自内部还是外部。本文将详细介绍它们以及它们的差异。
ClusterIP( 10.38.0.3) 只能从集群内部访问。要从集群外部访问服务,请尝试nodeIP:port 192.168.150.202:8080
\n\nNodePort 服务类型允许我们在静态端口的每个 Node\xe2\x80\x99s\nIP 上公开我们的服务。因此,它允许从集群外部访问服务。
\n
| 归档时间: |
|
| 查看次数: |
42114 次 |
| 最近记录: |