CSchantz Wiki

kubernetes Commands

List namespace, podname, and cluster name for primary on specific node

kubectl get pods -A --field-selector spec.nodeName=node# -l role=primary -o custom-columns='NS:.metadata.namespace,POD:.metadata.name,CLUSTER:.metadata.ownerReferences[0].name'

List all primary’s on a node

kubectl get pods -A -l role=primary -o wide | grep node#

List how many instances of a pod in a name space

kubectl get clustertype podcluster -n namespace -o jsonpath='{.spec.instances}{"\n"}'

List cluster pod/role/node per cluster

kubectl get pods -A -o custom-columns='NS:.metadata.namespace,POD:.metadata.name,CLUSTER:.metadata.ownerReferences[0].name,ROLE:.metadata.labels.role,NODE:.spec.nodeName,STATUS:.status.phase' | grep -e NS -e <clustername>

Quick use namespace and cluster to match pod Primary and replica

kubectl get pods -n NAMESPACE -o custom-columns='POD:.metadata.name,ROLE:.metadata.labels.role,NODE:.spec.nodeName,STATUS:.status.phase' | awk 'NR==1 || index($1,"CLUSTER-")==1'


Check configured instances of pods and how many are ready

kubectl get REAL-TYPE CLUSTER -n NAMESPACE -o jsonpath='wanted={.spec.instances}  ready={.status.readyInstances}{"\n"}'

Moving a node primary pod node to secondary/replica pod

List primary’s with info on node

kubectl get pods -A --field-selector spec.nodeName=node# -l role=primary -o custom-columns='NS:.metadata.namespace,POD:.metadata.name,CLUSTER:.metadata.ownerReferences[0].name'

List specific node primary and secondary attachment

kubectl get pods -n NAMESPACE -o custom-columns='POD:.metadata.name,ROLE:.metadata.labels.role,NODE:.spec.nodeName,STATUS:.status.phase' | awk 'NR==1 || index($1,"CLUSTER-")==1'

Get Cluster type

kubectl get pod POD-NAME -n NAMESPACE -o jsonpath='{.metadata.ownerReferences[0].kind}{"  "}{.metadata.ownerReferences[0].apiVersion}{"\n"}'

Move primary to secondary

kubectl -n NAMESPACE patch CLUSTER_REAL_TYPE CLUSTER --subresource=status --type=merge -p '{"status":{"targetPrimary":"TARGET-POD"}}'