- Restart deployments pods after a configmap change
- Deleted failed pods or jobs
- GCE: Run Container with a volume mounted
- GKE: Get the name of the cluster
- GKE: Remove a node from a cluster
- GKE: Access kube-api logs
date --utc '+{"spec": {"template": {"metadata": {"creationTimestamp": "%FT%TZ"}}}}' > /dev/shm/$$.json
kubectl -n namespaceName patch deploy/deploymentName -p "$(cat /dev/shm/$$.json)"
For pods:
kubectl get pods -n NS --field-selector=status.phase=Failed | awk '{ if(NR>1)print $1}' | xargs kubectl delete pods -n NS
For pods, all namespaces:
kubectl get pods --all-namespaces --field-selector=status.phase=Failed | awk '{ if(NR>1)print $1 " " $2}' | xargs kubectl delete pods -n
For jobs:
kubectl get jobs -n NS -o json | jq -r '.items[] | select(.status.conditions[].type=="Failed") | .metadata.name' | xargs kubectl -n NS delete job
kubectl run -i --rm --tty ubuntu --overrides='
{
"spec": {
"containers": [
{
"name": "ubuntu",
"image": "ubuntu:latest",
"args": [
"bash"
],
"stdin": true,
"stdinOnce": true,
"tty": true,
"volumeMounts": [{
"mountPath": "/volume",
"name": "volume-disk"
}]
}
],
"volumes": [{
"name":"volume-disk",
"gcePersistentDisk": {"pdName": "DISK-NAME", "fsType": "ext4"}
}]
}
}
' --image=ubuntu:latest --restart=Never -- /bin/bash
In GKE, this command returns the name of the cluster where it's running:
curl -s http://metadata/computeMetadata/v1/instance/attributes/cluster-name -H "Metadata-Flavor: Google"
This is a method to size down a pool by removing a node.
kubectl cordon NODE
kubectl drain NODE --ignore-daemonsets
gcloud compute instances describe --format='value[](metadata.items.created-by)' NODE
gcloud compute instance-groups managed delete-instances GROUP --instances=NODE --zone=ZONE
delete-instances scales down by 1 the node pool.
kubectl proxy --port=8080 &
curl -s localhost:8080/logs/kube-apiserver.log