How to delete kubernetes dashboard ui pod using kubectl - kubernetes

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

Related

Pods not found while using kubectl port-forward

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>

pods "kubernetes-dashboard-7ffd448895-56tlr" not found

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.

how to fix coredns service not found after initializing pod network

I started with Kubernetes tutorial and after intializeing the pod network
kubectl apply -f https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml
I discovered that coredns is pending but rest of the services were running.
# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-74ff55c5b-gzn5l 0/1 Pending 0 19m
kube-system coredns-74ff55c5b-k2h5m 0/1 Pending 0 19m
the I tried to look at the logs:
# kubectl logs coredns-74ff55c5b-gzn5l
Error from server (NotFound): pods "coredns-74ff55c5b-gzn5l" not found
# kubectl logs coredns-74ff55c5b-k2h5m
Error from server (NotFound): pods "coredns-74ff55c5b-k2h5m" not found

Kubernetes dashboard pods is not running

I'd set up kubernetes with kubeadm, and launched dashboard by:
kubectl apply -f
https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
and checked pod status:
kubectl gets pods --all-namespaces
But it is not running. It's in "containerCreating" status.
kube-system kubernetes-dashboard-5bd6f767c7-v5g8q 0/1
ContainerCreating 0 29m
I checked log by:
kubectl logs kubernetes-dashboard-5bd6f767c7-v5g8q
--namespace=kube-system
And it says:
Error from server (BadRequest): container "kubernetes-dashboard" in
pod "kubernetes-dashboard-5bd6f767c7-v5g8q" is waiting to start:
ContainerCreating
I did all the steps to install the dashboard. But not sure what's wrong here.
Would you like to help me?

Can't delete pods in pending state?

[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