Skip to content

Instantly share code, notes, and snippets.

@rvanbutselaar
Last active December 9, 2021 12:42
Show Gist options
  • Save rvanbutselaar/b1126e308a361c74d48132d7390e1c5e to your computer and use it in GitHub Desktop.
Save rvanbutselaar/b1126e308a361c74d48132d7390e1c5e to your computer and use it in GitHub Desktop.
# Install OpenShift 3.11 cli
brew install https://raw.githubusercontent.com/cblecker/homebrew-core/d1092419e5113b296a6b1d7ecd2bf6673d39f0a2/Formula/openshift-cli.rb
# ID = /var/lib/origin/openshift.local.volumes/plugins/kubernetes.io/cinder/mounts/[ID]
oc get pv -o json | jq -r '[.items[] | {name:.spec.claimRef.name, namespace:.spec.claimRef.namespace, volumeID:.spec.cinder.volumeID}]' | grep -n2 [ID]
# ElasticSearch get incides
oc -n openshift-logging rsh $(oc -n openshift-logging get po -l component=es -o name) es_util --query=_cat/indices -XCURL
# Fix OCP 3.11 curator
oc -n openshift-logging set image cronjob logging-curator curator=registry.redhat.io/openshift3/ose-logging-curator5:v3.11.16 && \
oc -n openshift-logging create job --from=cronjob/logging-curator logging-curator
# loop namespaces and get networkpolicy,egressnetworkpolicies
for ns in `oc get namespaces -o=jsonpath='{.items[*].metadata.name}'`; do
echo '--'
echo $ns
oc -n $ns get networkpolicy,egressnetworkpolicies
echo '--'
done
# get images used inside a namespace
oc get po -o jsonpath="{..image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c
# get images used inside all namespace
for ns in `oc get ns -o jsonpath='{..metadata.name}'`; do oc -n $ns get po -o jsonpath="{..image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c; done
# get resource usage of all worker/compute nodes
for i in $(oc get nodes --no-headers | awk '{print $1}' | sort -V | grep compute); do echo $i && oc describe node $i | grep -A5 '^Allocated resources' ;done
# scale all dc's to one
for dc in `oc get dc -o jsonpath='{.items[*].metadata.name}'`; do echo $dc; oc scale dc/$dc --replicas=1; done
# change all route's inside a project
for r in `oc get route -o jsonpath='{.items[*].metadata.name}'`; do
echo $r;
url=$(oc get route $r -o jsonpath='{..spec.host}');
echo $url;
oc patch route/$r -p '{"spec":{"host":"'$(echo $url | sed -e "s/dev/prod/g")'"}}';
done
# Get CPU requests/limits
oc get dc -o custom-columns=Name:.metadata.name,CPUReq:.spec.template.spec.containers[*].resources.requests.cpu
oc get dc -o custom-columns=Name:.metadata.name,CPULimit:.spec.template.spec.containers[*].resources.limits.cpu
# Get Memory requests/limits
oc get dc -o custom-columns=Name:.metadata.name,MEMReq:.spec.template.spec.containers[*].resources.requests.memory
oc get dc -o custom-columns=Name:.metadata.name,MEMLimit:.spec.template.spec.containers[*].resources.limits.memory
# Restart all pods with CrashLoopBackOff status in cluster
oc get po -o wide --all-namespaces | grep CrashLoopBackOff| awk '{print "oc -n " $1 " delete po --wait=false " $2}' | sh
# Loop OpenShift projects and get image & imagePullPolicy
for ns in default glusterfs kube-service-catalog kube-system openshift openshift-console openshift-infra openshift-logging openshift-metrics-server openshift-node openshift-sdn openshift-template-service-broker openshift-web-console; do
for p in `oc -n $ns get po -o=jsonpath='{..metadata.name}'`; do
oc -n $ns get po $p -o=jsonpath='{..spec.containers[*].image}{","}{..spec.containers[*].imagePullPolicy}{"\n"}';
done
done
# wait for deployment to finish
until [ $(oc get po -l deploymentconfig=tomcat-as -o jsonpath='{..status.containerStatuses[?(@.name=="tomcat-as")].ready}') == "true" ]
do
oc get po -l deploymentconfig=tomcat-as --no-headers
sleep 30
done
# wait for sts to finish
until [ $(oc get sts/tomcat-as-background -o jsonpath='{.status.readyReplicas}') == "2" ]
do
oc get po -l deploymentconfig=tomcat-as-background --no-headers
sleep 30
done
# wait for job or pod to finish
until [ $(oc get po/tomcat-import -o jsonpath='{..status.phase}') == "Succeeded" ]
do
oc get po/tomcat-import --no-headers
sleep 3
done
# send test alert via prometheus
oc -n monitoring rsh -c prometheus $(oc -n monitoring get po -l app=prometheus -o name|head -n1) curl -H "Content-Type: application/json" -d '[{"labels":{"alertname":"TestAlert1"}}]' alertmanager:9093/api/v1/alerts
# get configmap value in json format
oc get cm grafana-dashboard-alertmanager-alerts -o json | jq -r ".data|.[]"
# get configmap json
oc get secret pull-secret -o json | jq -r '.data[".dockerconfigjson"]' | base64 -d | grep -c cloud.openshift.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment