Score:0

How can I restart or reset the custom namespace pods

ar flag

I have a k3s cluster with kube-system pods and my application's (xyz-system namespace) pods:

kube-system   pod/calico-node-xxxx                          
kube-system   pod/calico-kube-controllers-xxxxxx   
kube-system   pod/metrics-server-xxxxx
kube-system   pod/local-path-provisioner-xxxxx
kube-system   pod/coredns-xxxxx
xyz-system    pod/my-app
xyz-system    pod/my-app-mqtt

I want to reset/restart all of these pods (kube-system + xyz-system) in one command (or it can be two commands for two namespace but without deployment name) without giving deployment names because in future I can have more deployments created, so it will be difficult to provide many deployment names manually.

Debugging:
With command kubectl -n kube-system rollout restart daemonsets,deployments as mentioned in link I am able to restart the kube-system pods. But when I modify this command with xyz-namespace : kubectl -n xyz-system rollout restart deployments the respective pods are not restarting when I monitor watch kubectl get all -A they remain as it is in Running state.

Can someone let me know how to achieve this ?

jp flag
But why would you want to restart them? it is against the principles k8s is built for
solveit avatar
ar flag
@Jonas: I want to understand more about what you said that "its against the principle....". Can you provide any k3s/k8s official doc from where it can be evident ?
jp flag
Pods are disposable, e.g. immutable architecture - you don't mutate, but throw away (delete) and instead create new pods. It is not intended to change anything about a Pod. See e.g. https://kubernetes.io/docs/concepts/workloads/pods/#working-with-pods
Score:4
hk flag
SYN

In two commands:

kubectl delete pod -n kube-system --all
kubectl delete pod -n xyz-system --all

In "one":

kubectl get pods -A | awk 'NR>1{print $1" "$2}' \
    | while read ns pod; do \
        kubectl delete -n $ns pod $pod; done

Or:

kubectl get ns | awk 'NR>1{print $1}' \
    | while read ns; do \
         kubectl delete pod -n $ns --all; done

Though I second @jonas comment: sounds like a weird question, with no real-life use cases that I know of.

p10l avatar
us flag
Or you could issue `kubectl delete pod --all --all-namespaces`, but this will restart (or delete if not in deployment) absolutely everything.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.