How to Check Pod IP Addresses in Azure Kubernetes Service (AKS)

How to Check Pod IP Addresses in Azure Kubernetes Service (AKS)

 Azure Kubernetes Service (AKS) runs containerized applications using Kubernetes Pods. Each Pod receives an IP address that enables communication within the cluster. Checking Pod IP addresses is useful for troubleshooting network connectivity and identifying application instances.

1. Connect to AKS

Log in to Azure and connect to your AKS cluster:

az login
az aks get-credentials \
  --resource-group <ResourceGroupName> \
  --name <AKSClusterName>

2. Check All Pod IP Addresses

Run the following command to view all Pods with their IP addresses and worker nodes:

kubectl get pods -A -o wide

The output includes Pod names, namespaces, Pod IPs, and node information.

3. Check Pods in a Specific Namespace

To check Pods running in the production namespace:

kubectl get pods -n production -o wide

4. Get a Specific Pod IP

Use JSONPath to retrieve the IP address of an individual Pod:

kubectl get pod <PodName> -n <Namespace> \
-o jsonpath='{.status.podIP}'

5. Check Pod and Node IPs Together

To identify both Pod IP and worker node IP:

kubectl get pods -A \
-o custom-columns="POD:.metadata.name,POD-IP:.status.podIP,NODE-IP:.status.hostIP"

6. Check Service Endpoints

To identify which Pod IP addresses are associated with a Kubernetes Service:

kubectl get endpoints <ServiceName> -n <Namespace>

Best Practice

Avoid hardcoding Pod IP addresses in application configurations because they can change when Pods restart or are recreated. Instead, use Kubernetes Service DNS for reliable internal communication.

For example:

http://myapp-service.production.svc.cluster.local

Conclusion

Using simple kubectl commands, DevOps engineers can quickly identify Pod IP addresses, inspect worker nodes, and troubleshoot application connectivity in Azure Kubernetes Service (AKS).

Post a Comment

0 Comments