This is my Pod manifest:
apiVersion: v1
kind: Pod
metadata:
name: pod-nginx-container
spec:
containers:
- name: nginx-alpine-container-1
image: nginx:alpine
ports:
- containerPort: 80
Below is output of my "kubectl describe pod" command:
C:Usersso.userDesktop>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
I couldn’t understand what is IP address mentioned in "IPs:" field of this output. I am sure this is not my Node’s IP, so I am wondering what IP is this. And please note that I have not exposed a Service, infact there is no Service in my Kubernetes cluster, so I not able to figure out this.
Also, how "Port" and "Host Port" are different, from Googling I could understand little bit but if someone can explain with an example then it would be great.
NOTE: I have already Googled "explanation of kubectl describe pod command" and tried searching a lot, but I can’t find my answers, so posting this question.
3
Answers
PodIP is the local ip of the pod within the cluster. Each pod gets a dynamic IP allocated to it.
You can see the explanation from
kubectl
commandThats pod’s ip.
Every Pod gets its own IP address.
When you will create service, the service will internally map to this pod’s ip.
If you delete the pod and recreate it again. you will notice a new ip. thats the reason why it is recommended to create service object which will keep track of pod’s ip based on label selector.
Found this image online to explain
I dont know about the difference between port and hostport field under containerSpec.
Pods
A pod in Kubernetes is the smallest deployment unit. A pod is a group of one or more containers. The containers in a pod share storage and network resources.
Pod networking
In Kubernetes, each pod is assigned a unique IP address, this IP address is local within the cluster. Containers within the same pod use
localhost
to communicate with each other. Networking with other pods or services is done with IP networking.When doing
kubectl describe pod <podname>
you see the IP address for the pod.See Pod networking
Application networking in a cluster
A pod is a single instance of an application. You typically run an application as a Deployment with one ore more replicas (instances). When upgrading a Deployment with a new version of your container image, new pods is created – this means that all your instances get new IP addresses.
To keep a stable network address for your application, create a Service – and always use the service name when sending traffic to other applications within the cluster. The traffic addressed to a service is load balanced to the replicas (instances).
Exposing an application outside the cluster
To expose an application to clients outside the cluster, you typically use an Ingress resource – it typically represents a load balancer (e.g. cloud load balancer) with reverse proxy functionality – and route traffic for some specific paths to your services.