Trouble with Kubernetes node port

Summary

The issue at hand is related to accessing a front-end application deployed on a Kubernetes pod using Minikube. The application is not accessible on the expected NodePort, which is 30100. The setup involves a React app, a Dockerfile for building and running the app, and Kubernetes configurations for deploying the application.

Root Cause

The root cause of the issue is related to the Kubernetes NodePort configuration and the service exposure. The key points to consider are:

  • The NodePort range in Kubernetes is 30000-32767.
  • The targetPort in the service configuration should match the port exposed by the Docker container.
  • The BACKEND_URL environment variable is set to http://server-service:8081, which might not be accessible from the Minikube IP.

Why This Happens in Real Systems

This issue occurs in real systems due to:

  • Misconfiguration of Kubernetes services and NodePort ranges.
  • Incorrect exposure of Docker container ports.
  • Insufficient understanding of Minikube networking and Kubernetes cluster setup.
  • Environment variable misconfiguration, such as the BACKEND_URL.

Real-World Impact

The impact of this issue includes:

  • Inability to access the front-end application from outside the Kubernetes cluster.
  • Difficulty in debugging and troubleshooting the application.
  • Potential security risks due to exposed ports and incorrect CORS configuration.
  • Delays in development and deployment of the application.

Example or Code

# Verify the Kubernetes service configuration
kubectl get svc -o yaml

# Check the NodePort range
kubectl get svc -o jsonpath='{.items[0].spec.ports[0].nodePort}'

# Verify the Docker container port exposure
docker ps -a --format '{{.Ports}}'

How Senior Engineers Fix It

To fix this issue, senior engineers would:

  • Verify the Kubernetes service configuration and NodePort range.
  • Check the Docker container port exposure and targetPort configuration.
  • Review the BACKEND_URL environment variable and CORS configuration.
  • Use tools like kubectl and docker to debug and troubleshoot the issue.

Why Juniors Miss It

Junior engineers might miss this issue due to:

  • Lack of understanding of Kubernetes and Docker concepts.
  • Insufficient experience with Minikube and Kubernetes cluster setup.
  • Overlooking the importance of NodePort range and targetPort configuration.
  • Not thoroughly reviewing environment variable configurations, such as BACKEND_URL.