kubectl port-forward — port tunneling.
1# Pod2kubectl port-forward pod_name 3000:30003kubectl port-forward pod_name 3000:3000 -n production45# Service6kubectl port-forward svc/service_name 8080:807kubectl port-forward svc/service_name 8080:80 -n production89# Database (PostgreSQL)10kubectl port-forward svc/postgres 5432:543211psql -h localhost -p 5432 -U postgres1213# Redis14kubectl port-forward svc/redis 6379:637915redis-cli -h localhost -p 63791617# Debugging18kubectl port-forward pod_name 3000:3000 &19curl http://localhost:300020kill %1 # Stop the tunnel2122# SSH tunnel23kubectl port-forward svc/bastion 2222:2224ssh -p 2222 user@localhost
Use cases: