Difference between revisions of "Kubectl port-forward"
Jump to navigation
Jump to search
Line 58: | Line 58: | ||
* <code>[[kubectl get services]]</code> | * <code>[[kubectl get services]]</code> | ||
* [[kubectl create service clusterip]] | * [[kubectl create service clusterip]] | ||
+ | * [[kubectl tunnel]] | ||
== See also == | == See also == |
Revision as of 13:28, 30 November 2023
kubectl port-forward
forward one or more local ports to a pod.
- Man: https://www.mankier.com/1/kubectl-port-forward
kubectl port-forward --help
kubectl port-forward deployment/mydeployment 8080:443
Examples
- Grafana:
kubectl --namespace default port-forward $POD_NAME 3000
- Prometheus:
kubectl --namespace default port-forward $POD_NAME 9090
kubectl port-forward --namespace default svc/prometheus-kube-prometheus-prometheus 9090:9090
- Alertmanager:
kubectl port-forward --namespace default svc/prometheus-kube-prometheus-alertmanager 9093:9093
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace default port-forward $POD_NAME 3000 Forwarding from 127.0.0.1:3000 -> 3000 Forwarding from [::1]:3000 -> 3000
kubectl -n default port-forward $POD_NAME 8443:8443 Forwarding from 127.0.0.1:8443 -> 8443 Forwarding from [::1]:8443 -> 8443 kubectl -n your-namespace port-forward service/pritunl-ui 7111:443
List of ports, do not included port-forward
ports:
kubectl get svc --all-namespaces -o json | jq '.items[] | {name:.metadata.name, p:.spec.ports[] } | select( .p.nodePort != null ) | "\(.name): localhost:\(.p.nodePort) -> \(.p.port) -> \(.p.targetPort)"'
Examples with errors
kubectl --namespace default port-forward $POD_NAME 3000 error: unable to forward port because pod is not running. Current status=Failed
kubectl --namespace default port-forward $POD_NAME 3000 error: unable to forward port because pod is not running. Current status=Pending
kubectl --namespace default port-forward $POD_NAME 3000 error: You must be logged in to the server (Unauthorized)
kubectl --namespace default port-forward $POD_NAME 3000 error: TYPE/NAME and list of ports are required for port-forward See 'kubectl port-forward -h' for help and examples
bind: address alredy in use unable to create listener
Solution: lsof -i
Related
kubectl get pods
- Port forwarding
kubectl proxy
- Kubernetes networking
kubectl get services
- kubectl create service clusterip
- kubectl tunnel
See also
kubectl port-forward [ --help ]
- Kubernetes networking: network policies, Network Policy Providers, CNI, Calico, flannel, Service mesh, Istio,
kube-proxy, coredns, AWS VPC CNI: vpc-cni
, Kubernetes: Ingress controllers, IPVS, ServiceTypes:LoadBalancer, ClusterIP, NodePort, ExternalName
, Endpoints, EndpointSlices, Kubernetes DNS,svc.cluster.local
, Weave Net - Kubernetes services,
kubectl get services, kubectl describe service
,kubectl create service
[loadbalancer
|nodeport
|clusterip
|externalname ], kubectl expose
,headless service, service.beta.kubernetes.io
Advertising: