Kubernetes,无法使用外部 IP 地址访问 Pod

问题描述

我是 Kubernetes 的新手,我遇到了一些问题。

我有一个 ubuntu 服务器,我正在处理它。我创建了 pod 和服务,还有一个 api-gateway pod 和服务。我想通过我的 PC 使用我的 ubuntu 服务器 IP 地址访问这个 pod。

但是我无法从服务器外部访问此 pod。 我在 docker 镜像上的应用在 80 端口上运行。

我的 api-gateway.yaml 文件是这样的:

apiVersion: apps/v1
kind: Deployment
Metadata:
  name: api-gateway
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api-gateway
  template:
    Metadata:
      labels:
        app: api-gateway
    spec:
      containers:
        - name: api-gateway
          image: myapi/api-gateway
---
apiVersion: v1
kind: Service
Metadata:
  name: api-gateway
spec:
  selector:
    app: api-gateway
  ports:
    - name: api-gateway
      protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30007
  type: NodePort
  externalIPs:
  - <My Ubuntu Server IP Adress>

当我输入 kubectl get services api-gateway 时,我得到

NAME           TYPE       CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
api-gateway   NodePort   10.104.42.32   <MyUbuntuS IP>   80:30007/TCP   131m

同样,当我输入 kubectl describe services api-gateway 时,我得到

Name:                     api-gateway
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=api-gateway
Type:                     NodePort
IP Families:              <none>
IP:                       10.104.42.32
IPs:                      10.104.42.32
External IPs:             <My Ubuntu Server IP Adress>
Port:                     api-gateway  80/TCP
TargetPort:               80/TCP
NodePort:                 api-gateway  30007/TCP
Endpoints:                172.17.0.4:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason  Age                  From                Message
  ----    ------  ----                 ----                -------
  normal  Type    30m                  service-controller  ClusterIP -> LoadBalancer
  normal  Type    6m10s                service-controller  NodePort -> LoadBalancer
  normal  Type    77s (x2 over 9m59s)  service-controller  LoadBalancer -> NodePort

那么,如何在我的 PC 浏览器或 Postman 上访问此 Pod?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)