Skip to content

Instantly share code, notes, and snippets.

@nolte
Last active September 13, 2020 20:25
Show Gist options
  • Save nolte/19106cbbcf17a4578374f4e6496b1390 to your computer and use it in GitHub Desktop.
Save nolte/19106cbbcf17a4578374f4e6496b1390 to your computer and use it in GitHub Desktop.
K8S Spicker

Delete pods by name

kubectl delete pod -n pfm-utilities $(kubectl get pods -n pfm-utilities -ocustom-columns=NAME:.metadata.name | grep manual)
kubectl delete job -n pfm-utilities $(kubectl get job -n pfm-utilities -ocustom-columns=NAME:.metadata.name | grep manual)
 oc get nodes --selector='failure-domain.beta.kubernetes.io/zone=eu-de-01'
kubectl get secrets -n baseline \
 -l jenkins-cr=p3s-jenkins-jenkins-helm-chart \
 -ojson | jq -j '.items[0].data.password' | base64 --decode
kubectl get secrets -n baseline --field-selector=type=Opaque

Debug Pod

kubectl run -i --rm --tty busybox --overrides='
{
 "spec": {

       "containers": [
         {
           "name": "busybox",
           "image": "busybox:latest",
           "args": [
             "sh"
           ],
           "stdin": true,
           "stdinOnce": true,
           "tty": true,
           "volumeMounts": [{
             "mountPath": "/sometest/store",
             "name": "store"
           }]
         }
       ],
       "volumes": [{
         "name":"store",
         "emptyDir":{}
       }]
 }
}
'  --image=busybox:latest --namespace=minecraft --restart=Never -- sh 

Debug Container with common tools

kubectl run -i --rm --tty busybox --overrides='
{
 "spec": {

       "containers": [
         {
           "name": "centos",
           "image": "centos:7",
           "args": [
             "sh"
           ],
           "stdin": true,
           "stdinOnce": true,
           "tty": true,
           "nodeSelector": {
               "beta.kubernetes.io/arch": "amd64"
           },
           "volumeMounts": [{
             "mountPath": "/sometest/store",
             "name": "store"
           }]
         }
       ],
       "volumes": [{
         "name":"store",
         "emptyDir":{}
       }]
 }
}
'  --image=centos:7 --namespace=monitoring-presentation --restart=Never -- sh 
kubectl run -i --rm --tty busybox --overrides='
{
    "spec": {
        "containers": [
            {
                "name": "busybox",
                "image": "busybox:latest",
                "args": [
                    "sh"
                ],
                "stdin": true,
                "stdinOnce": true,
                "tty": true,
                "volumeMounts": [
                    {
                        "mountPath": "/data",
                        "name": "store"
                    }
                ]
            }
        ],
        "volumes": [
            {
                "name": "store",
                "persistentVolumeClaim": {
                    "claimName": "mc-restored-2"
                }
            }
        ]
    }
}
'  --image=busybox:latest --namespace=minecraft --restart=Never -- sh 

hack fix terminated volume

kubectl patch pvc mc-restored -p '{"metadata":{"finalizers":null}}' -n minecraft

Remove Namespaces if Terminating

for ns in $(kubectl get ns --field-selector status.phase=Terminating -o jsonpath='{.items[*].metadata.name}'); do  kubectl get ns $ns -ojson | jq '.spec.finalizers = []' | kubectl replace --raw "/api/v1/namespaces/$ns/finalize" -f -; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment