kubectl run nginx --image=nginx --restart=Never
kubectl describe pod nginx
Node: node01/172.17.0.36
IP: 10.32.0.2
#we can reach nginx with the "IP" address
curl 10.32.0.2:80
but "curl 172.17.0.36:80" doesn't work!
kubectl describe nodes node01
InternalIP: 172.17.0.36
10.32.0.2 is the Pod's IP (=same IP for all containers running in that Pod):
kubectl exec -ti nginx bash
hostname -i
10.32.0.2
The Node IP cannot be used as such to reach the Pod/Container.
Setting the spec.container.ports.containerPort will not change neither the IP nor the POrt at which nginx is running: this parameter is purely "declarative" and is only useful when exposing the Pod/Deployment with a Service.
If you want to "expose" to an IP other than the Pod's IP:
kubectl expose pod nginx --port=8089 --target-port=80
kubectl describe service nginx
Type: ClusterIP
IP: 10.99.136.123
Port:
TargetPort: 80/TCP
Endpoints: 10.32.0.2:80
NB this IP 10.99.136.123 is NOT the Node's IP nor the Pod's IP. It's a service-specific IP.
curl 10.99.136.123:8089
kubectl get service --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default nginx ClusterIP 10.99.136.123
Ref:
https://kubernetes.io/docs/concepts/cluster-administration/networking/
No comments:
Post a Comment