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

时间:2021-02-17 21:08:19

标签: docker kubernetes kubectl kubeadm

我是 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?

0 个答案:

没有答案