外部网络访问K8S的POD服务端口简单实现

[[email protected] yml]# cat hostpath.yml 
apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: nginx
    name: test-container
    ports:
    - containerPort: 80
      hostPort: 8081
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /75shell/yml

 

外部网络访问K8S的POD服务端口简单实现

[[email protected] yml]# kubectl create -f hostpath.yml 
pod/test-pd created
[[email protected] yml]# kubectl get pods
NAME                READY   STATUS              RESTARTS   AGE
my-nginx-8lrhs      1/1     Running             0          32m
redis-slave-w5qzn   0/1     Terminating         0          7d23h
test-pd             0/1     ContainerCreating   0          5s
[[email protected] yml]# kubectl get pods
NAME                READY   STATUS        RESTARTS   AGE
my-nginx-8lrhs      1/1     Running       0          38m
redis-slave-w5qzn   0/1     Terminating   0          7d23h
test-pd             1/1     Running       0          5m33s
[[email protected] yml]# kubectl get po -o wide
NAME                READY   STATUS        RESTARTS   AGE     IP            NODE   NOMINATED NODE   READINESS GATES
my-nginx-8lrhs      1/1     Running       0          38m     172.30.94.2   v75    <none>           <none>
redis-slave-w5qzn   0/1     Terminating   0          7d23h   <none>        v77    <none>           <none>
test-pd             1/1     Running       0          6m17s   172.30.91.2   v76    <none>           <none>

 

此时通过访问POD所在NODE的IP和映射的端口就能访问POD的服务了

外部网络访问K8S的POD服务端口简单实现