Cannot delete failed pod in Kubernetes Dashboard - docker

I'm trying to delete a failed pod from the Pods page on the Kubernetes Web UI, but it is not getting deleted.
I understand what the error itself is, and I believe I have resolved it by using secrets, since this is a private repo. That said, I cannot re-add the pod again correctly, since it already exists.
Here is what I am seeing on the Pods page in the Kubernetes UI:
Pod Status: Waiting: ContainerCreating
Error:
Failed to pull image "<USERNAME>/<REPO>:<TAG>":
failed to run [fetch --no-store docker://<USERNAME>/<REPO>:<TAG>]:
exit status 254 stdout: stderr: Flag --no-store has been deprecated,
please use --pull-policy=update fetch: Unexpected HTTP code: 401, URL: https://xxxxxx.docker.io/v2/<USERNAME>/<NAMESPACE>/manifests/<TAG>
Error syncing pod
I have also tried deleting the pod with kubectl, but kubectl can't even see the failed pod!
$ kubectl get pods
No resources found
$ kubectl get pods --show-all
No resources found
Is there any other way that I can delete this pod?

I just found a solution to my own problem. Go to the Workloads page in the Kubernetes Web UI, and delete the associated Deployment, and the Pod will be deleted as well.
If the pod does not get deleted after this, you will need to force a delete from the command line.
kubectl delete pod <POD_NAME> --grace-period=0 --force

Use command below to delete terminated or failed one:
kubectl delete pods pod_name --grace-period=0 --force -n namespace_name

Related

For Kubernetes pods how to find cause of exit code 2

I have pods that are of kind Cronjob running in parallel. They complete task and run again after fixed interval of 20 minutes as per cron expression. I noticed that some pods are restarting 2-3 times before completing task.
I checked details in kubectl describe pod command and found that pod exit code 2 when it restart due to some error:
Last State: Terminated
Reason: Error
Exit Code: 2
I searched about exit code 2 and found that it is misuse of a shell builtin commands. How I can find which shell builtin is misused. How to debug cause of exit code 2.
Thanks in advance.
An exit code of 2 indicates either that the application chose to return that error code, or (by convention) there was a misuse of a shell built-in. Check your pod’s command specification to ensure that the command is correct. If you think it is correct, try running the image locally with a shell and run the command directly.
Refer to this link for more information.
You can get logs with
kubectl logs my-pod
Post output here if you can't fix it.

Kubernetes CronJob Pod status remains Running

I want to run a Kubernetes CronJob for a PHP script. Job executes properly but status of the POD remains running and after few minutes it becomes Error. It should be Completed status. Tried with different options but couldn't be able to resolve the issue.
Here is my CronJob Yaml file
Here is the output of kubectl get pods
Here is the log output inside the container.
Ignore the PHP exception. Issue is there regardless of the exception.
The state of the pod sets to completed when the running process / the application or the container returns exit code 0.
If in case it's returning a non-zero exit code it usually sets it to state Error.
If you want the pod set to completed status, just make sure the application at the end returning an exit code which is 0.
OPINION: It's something which is usual cases should be/are handled by the application itself.
I'm attaching docs for the k8s jobs.

Kubernete CreateContainerConfigError

I'm trying to deploy an app on k8s but I keep getting the following error
NAME READY STATUS RESTARTS AGE
pod_name 1/2 CreateContainerConfigError 0 26m
If I try to see what went wrong using kubectl describe pod pod_name I get the following error: Error from server (NotFound): pods "pod_name" not found
You didn't include the command that generated the output shown, so it's hard to tell. Perhaps you're looking at different namespaces?
One of the parameters key in the file was misspelling making the deploy fail. Unfortunately, the error message was not helpful...
CreateContainerConfigError means kubernetes is unable to find the configmap you have provided for volume.Make sure both pod and configmap are deployed in same namespace.
Do cross verify the name of configmap you have created and configmap name you have specified in pod volume definition is same.
the message Error from server (NotFound): pods "pod_name" not found is very clear for me that you deployed your pod in a different namespace
In your deployment yaml file check the value of namespace and execute the command
kubectl describe pod pod_name -n namespace_from_yaml_file

Error `Cross-device link` when set logrotate mode `create 0644 root root` in kubernetes

In order to rotate pod logs, logrotate pod is used in kubernetes. By default, logrotate will use copytruncate mode to create a new rotated file, however datadog cannot work well in this mode, failed to retrieve pod log occasionally.
So I try to set the mode to create 0644 root root, but the following error comes up
Cross-device link
And logrotate failed to rotate logs either.
Could someone help me to resolve this issue or is there any better practice on rotate pod logs?

Openshift : pods not being deleted

I have am using OpenShift 3, and have been trying to get Fabric8 setup.
Things havent been going to well, so I decided to remove all services and pods.
When I run
oc delete all -l provider=fabric8
The cli output claims to have deleted a lot of pods, however, they are still showing in the web console, and I can run the same command in the CLI again and get the exact same list of pods that OpenShift cli claims it deleted.
How do I actually delete these pods?
Why is this not working as designed?
Thanks
Deletion is graceful by default, meaning the pods are given an opportunity to terminate themselves. You can force a graceless delete with oc delete all --grace-period=0 ...
You can also delete the pod forcefully like below,it works fine
#oc delete all -l provider=fabric8 --grace-period=0 --force
Sadly Jordan's response did not work for me on openshift 3.6.
Instead I used the option --now equivalent to --grace-period=1

Resources