Some Tips and Tricks for OCP (openshift)
You will find here some all day work tips for OpenShift Cluster this tips works also for the origin version.
get nodeport
oc get svc <your-service> -o jsonpath='{.spec.ports[?(@)].nodePort}'
get all released pv
oc get pv \
--template='{{range .items}}{{if eq .status.phase "Released" }}{{.metadata.name}}{{"\n"}}{{end}}{{end}}' \
--all-namespaces
The output.
pv020-volume
pv021-volume
pv022-volume
pv023-volume
pv025-volume
pv027-volume
pv034-volume
pv037-volume
pv038-volume
pv039-volume
pv042-volume
pv043-volume
Cleanup Released pvs
⚠ | You need jq to execute the following snipplet
for i in $(oc get pv --template='{{range .items}}{{if eq .status.phase "Released" }}{{.metadata.name}}{{"\n"}}{{end}}{{end}}' --all-namespaces );
do
oc export pv $i -o json | jq 'del(.spec.claimRef)' > ${i}_no-claimRef.json
oc delete pv $i && oc create -f ${i}_no-claimRef.json
echo "rm -rf /mnt/$( echo $i|cut -d'-' -f1)/[a-z]*"
done
Running pods on Nodes
This command shows which pod runns on which node.
oc get po --all-namespaces \
-o go-template='{{range .items}}{{if eq .status.phase "Running" }}name: {{ printf "%19s" .metadata.name}}; Namespace: {{ printf "%15s" .metadata.namespace}}; Nodename: {{.spec.nodeName}}{{"\n"}}{{end}}{{end}}'
The output looks like this.
name: router-51-f9gc4; Namespace: dev-router; Nodename: app_n05
name: router01-4-8z5gb; Namespace: dev-router; Nodename: app_n01
name: router02-4-mvd8l; Namespace: dev-router; Nodename: app_n04
name: router03-3-vnkn2; Namespace: dev-router; Nodename: app_n04
name: router04-2-gp4r7; Namespace: dev-router; Nodename: app_n02
name: router05-4-hmhnb; Namespace: dev-router; Nodename: app_n02
name: router12-4-vrcgc; Namespace: dev-router; Nodename: app_n04
name: ap-6-btgqf; Namespace: dev01; Nodename: app_n05
name: ap-1-4rz89; Namespace: dev02; Nodename: app_n05
name: ap-haproxy-1-q7tvq; Namespace: dev03; Nodename: app_n02
name: ap-1-blb8p; Namespace: dev03; Nodename: app_n03
Print all labels
oc get node --show-labels --no-headers \
| perl -MData::Dumper -ane 'push(@{$hosts->{$F[0]}},split( "," , $F[5])) ; \
END {foreach (reverse sort { $hosts->{$a} <=> $hosts->{$b} } keys %{$hosts}){ \
printf("\n% 8s\n %s\n",$_,join( " ; " , @{$hosts->{$_}}) );}}'
Output
nodei01
beta.kubernetes.io/arch=amd64 ; beta.kubernetes.io/os=linux ; failure-domain.beta.kubernetes.io/zone=nova ; kubernetes.io/hostname=nodei01 ; logging-infra-fluentd=true ; node-role.kubernetes.io/compute=true ; region=primary ; role=infra ; router=yes ; zone=mgmt
nodei02
beta.kubernetes.io/arch=amd64 ; beta.kubernetes.io/os=linux ; failure-domain.beta.kubernetes.io/zone=nova ; kubernetes.io/hostname=nodei02 ; logging-infra-fluentd=true ; node-role.kubernetes.io/compute=true ; region=primary ; role=infra ; router=yes ; zone=mgmt