"kubectl describe pod"命令输出中的IP字段是什么

What is IP field in the output of "kubectl describe pod" command

这是我的 Pod 清单:

apiVersion: v1
kind: Pod
metadata:
  name: pod-nginx-container
spec:
  containers:
  - name: nginx-alpine-container-1
    image: nginx:alpine
    ports:
      - containerPort: 80

下面是我的“kubectl describe pod”命令的输出:

C:\Users\so.user\Desktop\>kubectl describe pod pod-nginx-container
Name:         pod-nginx-container
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Mon, 15 Feb 2021 23:44:22 +0530
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           10.244.0.29
IPs:
  IP:  10.244.0.29
Containers:
  nginx-alpine-container-1:
    Container ID:   cri-o://01715e35d3d809bdfe70badd53698d6e26c0022d16ae74f7053134bb03fa73d2
    Image:          nginx:alpine
    Image ID:       docker.io/library/nginx@sha256:01747306a7247dbe928db991eab42e4002118bf636dd85b4ffea05dd907e5b66
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 15 Feb 2021 23:44:24 +0530
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-sxlc9 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-sxlc9:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-sxlc9
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  7m52s  default-scheduler  Successfully assigned default/pod-nginx-container to minikube
  Normal  Pulled     7m51s  kubelet            Container image "nginx:alpine" already present on machine
  Normal  Created    7m50s  kubelet            Created container nginx-alpine-container-1
  Normal  Started    7m50s  kubelet            Started container nginx-alpine-container-1

我无法理解此输出的“IPs:”字段中提到的 IP 地址是什么。我确定这不是我节点的 IP,所以我想知道这是什么 IP。请注意,我没有公开服务,事实上我的 Kubernetes 集群中没有服务,所以我无法弄清楚这一点。

此外,“端口”和“主机端口”有何不同,从谷歌搜索我可以理解一点,但如果有人能举例说明那就太好了。

注意:我已经用谷歌搜索了“kubectl describe pod 命令的解释”并尝试搜索了很多,但我找不到我的答案,所以发布这个问题。

PodIP 是集群内pod 的本地ip。每个 pod 都会分配一个动态 IP。

可以从kubectl命令中看到解释

kubectl explain po.status.podIP
IP address allocated to the pod. Routable at least within the cluster.
Empty if not yet allocated.

那是 pod 的 ip。

每个 Pod 都有自己的 IP 地址。 当您创建服务时,该服务将在内部映射到此 pod 的 ip。

如果删除pod再重新创建。你会注意到一个新的 ip。这就是为什么建议创建服务对象的原因,该服务对象将根据标签选择器跟踪 pod 的 ip。 在网上找到这张图片来解释

我不知道 containerSpec 下 port 和 hostport 字段的区别。

Pods

Kubernetes中的一个pod是最小的部署单元。 Pod 是一组一个或多个容器。 pod 中的容器共享存储和网络资源。

Pod 网络

在 Kubernetes 中,每个 pod 都分配有一个 唯一的 IP 地址,这个 IP 地址在集群中是本地的。同一 pod 中的容器使用 localhost 相互通信。与其他 pods 或服务的联网是通过 IP 联网 .

完成的

执行 kubectl describe pod <podname> 时,您会看到 pod 的 IP 地址。

Pod networking

集群中的应用程序网络

pod 是应用程序的单个实例。您通常 运行 一个应用程序作为 Deployment 具有一个或多个副本(实例)。使用新版本的容器映像升级 Deployment 时,会创建 new pods - 这意味着您的所有实例都会获得新的 IP 地址。

要为您的应用程序保持稳定的网络地址,请创建一个 Service - 并在向集群内的其他应用程序发送流量时始终使用该服务名称。发往服务的流量负载均衡到副本(实例)。

在集群外公开应用程序

要向集群外的客户端公开应用程序,您通常使用 Ingress 资源 - 它通常表示具有 反向代理 [=44= 的负载均衡器(例如云负载均衡器) ] 功能 - 并将某些特定路径的流量路由到您的服务。