Skip to content

Instantly share code, notes, and snippets.

@prasanthkothuri
Last active May 31, 2023 07:20
Show Gist options
  • Save prasanthkothuri/6ad51c2038ab23e9ada7adaac1f67954 to your computer and use it in GitHub Desktop.
Save prasanthkothuri/6ad51c2038ab23e9ada7adaac1f67954 to your computer and use it in GitHub Desktop.

Link to the master - https://kubernetes.io/docs/reference/kubectl/cheatsheet/

list services

kubectl get services --all-namespaces

kubernetes dashboard

kubectl describe services/kubernetes-dashboard -n kube-system

get user token

kubectl -n $USER get secret $(kubectl -n $USER get secret | grep spark-token- | awk '{print $1}') -o json | jq -r '.data.token' | base64 --decode

Extract secrets from Kubernetes

kubectl get secrets/{secret_name} -n {namespace} --template='{{.data.{secret_key} | base64decode}}'
kubectl get secrets/tiller-secret -n magnum-tiller -o json -o go-template='{{index .data "ca.crt" | base64decode}}' > tls-ca.pem

quotas on namespaces

cat compute-resources.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-resources
spec:
  hard:
    pods: "40"
    requests.cpu: "160"
    requests.memory: 320Gi
    limits.cpu: "160"
    limits.memory: 320Gi
kubectl create -f ./compute-resources.yaml --namespace=NAMESPACE

delete pods

IFS=$'\n'
pods=$(kubectl get pods -A | grep -v Running | grep -v Completed | grep -v Pending)
unset IFS
for i in $pods; do a=( $i ); kubectl delete pod ${a[1]} -n ${a[0]}; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment