kubernetes - 无法访问 Kubernetes 中暴露的部署/pod

标签 kubernetes

我想首先说我不知道​​所涉及服务器的确切架构。我只知道它们是云上的 Ubuntu 机器。

我已经使用两台服务器设置了一个 1 主/1 worker k8s 集群。
kubectl cluster-info给我:

Kubernetes master is running at https://10.62.194.4:6443
KubeDNS is running at https://10.62.194.4:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

我创建了一个简单的部署,如下所示:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: nginx
  name: nginx-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      run: nginx
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80

它启动了一个暴露在容器端口 80 上的 nginx pod。

我已经使用以下方法公开了此部署:
kubectl expose deployment nginx-deploy --type NodePort

当我运行 kubectl get svc ,我得到:
nginx-deploy   NodePort    10.99.103.239   <none>        80:30682/TCP   29m
kubectl get pods -o wide给我:
nginx-deploy-7c45b84548-ckqzb   1/1     Running   0          33m   192.168.1.5   myserver1   <none>           <none>
nginx-deploy-7c45b84548-vl4kh   1/1     Running   0          33m   192.168.1.4   myserver1   <none>           <none>

由于我使用 NodePort 公开了部署,我的印象是我可以使用 < Node IP > : < Node Port > 访问部署

工作节点的节点 IP 是 10.62.194.5,当我尝试访问 http://10.62.194.5:30682我没有得到 nginx 登陆页面。

我不明白的一部分是当我这样做时 kubectl describe node myserver1 ,在我收到的长输出中,我可以看到:
Addresses:
  InternalIP:  10.62.194.5
  Hostname:    myserver1

为什么说InternalIP?我可以ping这个IP

编辑:sudo lsof -i -P -n | grep LISTEN 的输出
systemd-r   846 systemd-resolve   13u  IPv4  24990      0t0  TCP 127.0.0.53:53 (LISTEN)
sshd       1157            root    3u  IPv4  30168      0t0  TCP *:22 (LISTEN)
sshd       1157            root    4u  IPv6  30170      0t0  TCP *:22 (LISTEN)
xrdp-sesm  9840            root    7u  IPv6 116948      0t0  TCP [::1]:3350 (LISTEN)
xrdp       9862            xrdp   11u  IPv6 117849      0t0  TCP *:3389 (LISTEN)
kubelet   51562            root    9u  IPv4 560219      0t0  TCP 127.0.0.1:42735 (LISTEN)
kubelet   51562            root   24u  IPv4 554677      0t0  TCP 127.0.0.1:10248 (LISTEN)
kubelet   51562            root   35u  IPv6 558616      0t0  TCP *:10250 (LISTEN)
kube-prox 52427            root   10u  IPv4 563401      0t0  TCP 127.0.0.1:10249 (LISTEN)
kube-prox 52427            root   11u  IPv6 564298      0t0  TCP *:10256 (LISTEN)
kube-prox 52427            root   12u  IPv6 618851      0t0  TCP *:30682 (LISTEN)
bird      52925            root    7u  IPv4 562993      0t0  TCP *:179 (LISTEN)
calico-fe 52927            root    3u  IPv6 562998      0t0  TCP *:9099 (LISTEN)
ss -ntlp | grep 30682 的输出
LISTEN   0         128                       *:30682                  *:*

最佳答案

据我了解,您正在尝试访问 10.62.194.5来自不同子网中的主机,例如您的终端。在 Azure 中,我猜每个节点都有一个公共(public) IP 和一个私有(private) IP。因此,如果您尝试访问 Kubernetes Service从您的终端,您应该使用主机的公共(public) IP 和端口,并确保该端口在您的 Azure 防火墙中打开。

关于kubernetes - 无法访问 Kubernetes 中暴露的部署/pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57152888/

相关文章:

azure - 在 Azure 上创建 Kubernetes 集群时出错 - 错误 : "code": "PropertyChangeNotAllowed"

kubernetes - 将它连接到 istio 后,如何为我的 keycloak 实例创建 URL 前端

redis - 升级图表时 Helm 相关性更新

nginx - ingress-nginx 错误连接被拒绝

ssl - 域名(开发、暂存、生产)的最佳实践是什么?

ubuntu - 在这个 freeradius 配置中我缺少什么吗?

kubernetes - EKS-节点标签

apache-spark - 线程 "main"org.apache.spark.SparkException : Must specify the driver container image 中的异常

kubernetes - k8s pod 重新启动时如何对 prometheus 计数器求和

未使用 Keycloack/Dex 授权的 Kubernetes 仪表板