I want to forward the ports
kubectl port-forward ...
But for this I need to find out the name of pods, I run the command
kubectl -n main_sp get pods
Getting a list:
NAME READY STATUS RESTARTS AGE
main-ms-hc-78469b74c-7lfdh 1/1 Running 0 13h
I'm trying
kubectl port-forward main-ms-hc-78469b74c-7lfdh 8080:80
and I get
Error from server (NotFound): pods "main-ms-hc-78469b74c-7lfdh" not found
What am I doing wrong?
You need to mention the namespace too while using port-forward:
$ kubectl port-forward -n main_sp main-ms-hc-78469b74c-7lfdh 8080:80
To port-forward a pod:
$ kubectl port-forward -n <namespace> <pod-name> <local-port>:<target-port>
To port-forward a pod via service name:
$ kubectl port-forward -n <namespace> svc/<servic-name> <local-port>:<target-port>
Related
In our kube cluster we have 2 namespaces kafka1 kafka2
kubectl get endpoints -n kafka2
NAME ENDPOINTS AGE
kafka2-akhq 10.233.76.160:8080 26d
kafka2-connect-api 10.233.67.2:8083,10.233.76.173:8083,10.233.90.52:8083 28m
and
kubectl get endpoints -n kafka1
NAME ENDPOINTS AGE
kafka1-akhq 10.233.67.157:8080 9d
kafka1-connect-api 10.233.67.3:8083,10.233.76.127:8083,10.233.90.4:8083 15h
everything is same expect 1 is replace by 2 in yaml
When I enter to ingress-nginx pod:
kubectl exec -n ingress-nginx ingress-nginx-controller -it -- bash
I can only curl second connector:
bash-5.1$ curl 10.233.67.2:8083
{"version":"3.2.0","commit":"38103ffaa962ef50","kafka_cluster_id":"KAEfPEuHSR-8znSgxlzJyQ"}bash-5.1$
when I try ip from first I got no response:
bash-5.1$ curl 10.233.67.3:8083
^C
Any idea how I can debug more information or how to fix this issue ?
Currently I'm using microk8s to run local cluster.
When I run k get pods -A, this result shown
...
kube-system kubernetes-dashboard-7ffd448895-56tlr 1/1 Running 1 3d14h
...
Ok.. It means there's a pod kubernetes-dashboard running in kube-system namespace.
And I tried to port forward that pod 443 into 10443 and this result shows up
$ k port-forward kubernetes-dashboard-7ffd448895-56tlr 10443:443
Error from server (NotFound): pods "kubernetes-dashboard-7ffd448895-56tlr" not found
I mean, there it is. The pod is there. But it keeps denying it.
I don't understand this result and stuck with no progress.
How can I port-forward my pods?
The result of k get pods -A indicates that the pod is in the namespace kube-system. Unless a resource is in the default namespace, you must specify the namespace:
k port-forward -n kube-system kubernetes-dashboard-7ffd448895-56tlr 10443:443
Alternatively, you can update your context to use a different namespace by default:
kubectl config set-context --current --namespace=kube-system
After you do that you can work with resources in kube-system without setting -n kube-system.
I installed kubernetes dashboard ui , but the status is aways pending. Now I want to delete the pending pod . Query current pod:
[root#iZuf63refzweg1d9dh94t8Z ~]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system kubernetes-dashboard-7d75c474bb-b2lwd 0/1 Pending 0 8d
now I am trying to delete pod:
[root#iZuf63refzweg1d9dh94t8Z ~]# kubectl delete pod kubernetes-dashboard-7d75c474bb-b2lwd
Error from server (NotFound): pods "kubernetes-dashboard-7d75c474bb-b2lwd" not found
how to delete kubernetes dashboard pod?
You should either specify the namespace with your kubectl delete command or set the namespace context before executing the command.
kubectl config set-context --current --namespace=kube-system
kubectl delete pod kubernetes-dashboard-7d75c474bb-b2lwd
Unless you've previously specified it, kubectl operations default to being performed against the default namespace. You don't have a Pod called kubectl delete pod kubernetes-dashboard-7d75c474bb-b2lwd in the default namespace, but as you see in the kubectl get pod --all-namespaces output you do have it in the kube-system namespace. So, instead, do:
kubectl delete pod kubernetes-dashboard-7d75c474bb-b2lwd --namespace=kube-system
$ kubectl logs -n kube-system po/kube-dns-5d6f4dbccf-gt5j2
Error from server (BadRequest): a container name must be specified for pod kube-dns-5d6f4dbccf-gt5j2, choose one of: [kubedns dnsmasq sidecar]
root#k8s-server01:~/source/dns# kubectl logs -n kube-system po/kube-dns-5d6f4dbccf-gt5j2 -c kubedns
I1101 01:49:49.294664 1 dns.go:48] version: 1.14.10
F1101 01:49:49.364594 1 server.go:56] Failed to create a kubernetes client: open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directory
[root#vpct-k8s-1 kubernetes]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system kube-ui-v2-ck0yw 0/1 Pending 0 1h
[root#vpct-k8s-1 kubernetes]# kubectl get rc --all-namespaces
NAMESPACE CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
kube-system kube-ui-v2 kube-ui gcr.io/google_containers/kube-ui:v2 k8s-app=kube-ui,version=v2 1 1h
Can't delete pods in pending state?
kubectl get ns
kubectl get pods --all-namespaces
kubectl get deployment -n (namespacename)
kubectl get deployments --all-namespaces
kubectl delete deployment (podname) -n (namespacename)
Try the below command
kubectl delete pod kube-ui-v2-ck0yw --grace-period=0 --force -n kube-system
To delete a pod in the pending state, simply delete the deployment file by using kubectl.
Please check the below command:
kubectl delete -f deployment-file-name.yaml
Depending on the number of replicas you specified while creating the cluster, you might be able to delete the pending pod but another pod will be recreated automatically. You can delete the pod by running this command:
$ ./cluster/kubectl.sh delete pod kube-ui-v2-ck0yw