Skip to content

Instantly share code, notes, and snippets.

@eslutsky
Forked from tuxfight3r/openshift_cli_tricks.MD
Last active September 29, 2020 14:13
Show Gist options
  • Save eslutsky/4c22eab599923aef3e96c002b43fa20f to your computer and use it in GitHub Desktop.
Save eslutsky/4c22eab599923aef3e96c002b43fa20f to your computer and use it in GitHub Desktop.
openshift cli tricks - using go templates
#!/bin/bash
#following this guide https://access.redhat.com/solutions/4885641
#recommended threshond 10msec - should be below that value
fio_sync_thresh=10000000
while [ 1 ] ; do
cd /var/lib
tempd=$(mktemp -d -p `pwd`)
pushd $tempd
cat <<__EOF__ >etcd.fio
[global]
name=etcd-io
filename=/mount/etcd-io-delete-me
rw=write
bs=2300
fdatasync=1
[file1]
size=22M
ioengine=sync
__EOF__
#podman run --volume "$PWD:/mount:z" docker.io/ljishen/fio /mount/etcd.fio
podman run --volume "$PWD:/mount:z" docker.io/ljishen/fio /mount/etcd.fio --output-format json > /tmp/result.json
sync_99=$(cat /tmp/result.json | jq '.jobs[0].sync.lat_ns.percentile."99.000000"')
if (( $sync_99 > $fio_sync_thresh )) ; then
echo "fio performance $sync_99 below recommended threshold $fio_sync_thresh"
else
echo "fio performence is good $sync_99"
fi
popd
rm -rf $tempd
sleep 5
done

openshift list all pods and thier specs (requests/limits)

oc get pod -o jsonpath='{range .items[*]}{"SPEC:  \n  LIMITS  : "}{.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.containers[*].resources.requests}{"\n"}{end}'

openshift list all pods and thier specs with name (requests /limits)

oc get pod -o jsonpath='{range .items[*]}{"NAME:  "}{.metadata.name}{"\nSPEC:  \n  LIMITS  : "}{.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.containers[*].resources.requests}{"\n\n"}{end}'

openshift list all nodes and thier corresponding os/kernel verion

oc get nodes -o jsonpath='{range .items[*]}{"\t"}{.metadata.name}{"\t"}{.status.nodeInfo.osImage}{"\t"}{.status.nodeInfo.kernelVersion}{"\n"}{end}'

openshift patch build config with patch

oc patch bc/kube-ops-view -p '{"spec":{"resources":{"limits":{"cpu":"1","memory":"1024Mi"},"requests":{"cpu":"100m","memory":"256Mi"}}}}'

openshift display the images used by Replication Controller

oc get rc -n openshift-infra -o jsonpath='{range .items[*]}{"RC: "}{.metadata.name}{"\n Image:"}{.spec.template.spec.containers[*].image}{"\n"}{end}'

openshift display the requestor for namespace

oc get namespace ui-test -o template --template '{{ index .metadata.annotations "openshift.io/requester"  }}'

openshift display all projects and its creator sorted by creator

IFS=,; while read data1 data2; do printf "%-60s : %-50s\n" $data1 $data2; 
done < <( oc get projects -o template \
--template '{{range .items}}{{.metadata.name}},{{index .metadata.annotations "openshift.io/requester"}}{{"\n"}}{{end }}' |
sort -t, -k2 )

openshift fetch custom column name from metadata

oc get rolebinding -o=custom-columns=USERS:.userNames,GROUPS:.groupNames


for i in `oc get pv  -o=custom-columns=NAME:.metadata.name | grep pvc` ;
   do oc describe pv $i | grep Path |awk '{print $2}';
done

openshift-machine-api

oc get nodes 
oc project openshift-machine-api
oc get machine -o=custom-columns="name:.metadata.name,Status:status.phase,Address:.status.addresses[1].address,state:status.providerStatus.instanceState"

scaling up workers

oc get machineset
oc scale --replicas=1 machineset primary-w5bzm-worker-0  -n openshift-machine-api

troubleshooting the nodes

oc get nodes
oc debug node/primary-w5bzm-master-0

# change root to host
chroot /host

adding

["-device","virtio-serial","-chardev","file,id=virtioserial_ovirt11,path=/tmp/virtioserial_ovirt11_journal.log,append=on","-device", "virtserialport,chardev=virtioserial_ovirt11,name=com.coreos.ignition.journal"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment