Skip to content

Instantly share code, notes, and snippets.

Avatar
🇹🇼
o p e n

Phil Huang pichuang

🇹🇼
o p e n
View GitHub Profile
View shared-memory.yaml
---
apiVersion: v1
id: hello-openshift
kind: Pod
metadata:
name: hello-openshift
labels:
name: hello-openshift
spec:
volumes:
View Dockerfile-with-dnf
FROM registry.access.redhat.com/ubi8/ubi:8.3
RUN dnf -y install nginx && \
dnf -y clean all
View string.yml
PLAY [localhost] ***************************************************************
TASK [Test Case 1] *************************************************************
changed: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "who is handsome man? smallplane"
}
View node-loadtesting.yml
---
apiVersion: batch/v1
kind: Job
metadata:
generateName: work-queue-
spec:
template:
spec:
containers:
- name: work
@pichuang
pichuang / restore_etcd.sh
Created Feb 19, 2021
OCP 4.6.8 ETCD Restore
View restore_etcd.sh
#!/bin/bash
BACKUP_DIR="~/etcd_backup/backup/backup.epq0825v"
master_nodes=(master0.dmz.ocp4.local master1.dmz.ocp4.local master2.dmz.ocp4.local)
cd $BACKUP
for node in "${master_nodes[@]}"
do
scp -i ~/.ssh/dmz-ocp4-rsa $BACKUP_DIR/* core@$node:~/
ssh -i ~/.ssh/dmz-ocp4-rsa core@$node sudo /usr/local/bin/cluster-restore.sh /home/core/
@pichuang
pichuang / graceful_shutdown_ocp.sh
Last active Feb 19, 2021
Shutdown OCP4.6 Gracefully
View graceful_shutdown_ocp.sh
#!/bin/bash
# Ref: https://docs.openshift.com/container-platform/4.6/backup_and_restore/graceful-cluster-shutdown.html
# !!!IMPORTANT!!!
# DO THE ETCD BACKUP FISRT
# https://gist.github.com/pichuang/53aef7091245c55a91a5f0bd56fa3256
non_master_nodes=$(oc get nodes --selector='!node-role.kubernetes.io/master' -o jsonpath='{.items[*].metadata.name}')
for node in ${non_master_nodes[@]}
View defrag_etcd.sh
#!/bin/bash
etcd_node=`oc get pods -n openshift-etcd -l app=etcd -o=jsonpath='{.items[0].spec.nodeName}'`
ssh -i ~/.ssh/dmz-ocp4-rsa core@$etcd_node
id=$(sudo crictl ps --name etcdctl | awk 'FNR==2{ print $1}') && sudo crictl exec -it $id /bin/bash
ETCDCTL_ENDPOINTS=$(etcdctl member list | awk -F', ' '{printf "%s%s",sep,$5; sep=","}')
rev=$(etcdctl endpoint status --write-out="json" | egrep -o '"revision":[0-9]*' | egrep -o '[0-9]*' -m1)
etcdctl compact $rev
unset ETCDCTL_ENDPOINTS
etcdctl --command-timeout=30s --endpoints=https://localhost:2379 defrag
@pichuang
pichuang / check_etcd.sh
Last active Feb 22, 2021
Check etcd status on OCP 4.6.1
View check_etcd.sh
#!/bin/bash
# Ref: https://docs.openshift.com/container-platform/4.6/backup_and_restore/backing-up-etcd.html
etcd_node=`oc get pods -n openshift-etcd -l app=etcd -o=jsonpath='{.items[0].spec.nodeName}'`
ssh -i ~/.ssh/dmz-ocp4-rsa core@$etcd_node
id=$(sudo crictl ps --name etcdctl | awk 'FNR==2{ print $1}') && sudo crictl exec -it $id /bin/bash
etcdctl member list -w table
etcdctl endpoint health --cluster
@pichuang
pichuang / backup_etcd.sh
Last active Feb 19, 2021
OCP 4.6.1 ETCD Backup Shell Script
View backup_etcd.sh
#!/bin/bash
healthy=$(oc get etcd -o=jsonpath='{range .items[0].status.conditions[?(@.type=="EtcdMembersAvailable")]}{.message}{"\n"}')
if [ "$healthy" != "3 members are available" ]; then
echo "check to see if something is broken"
exit 1
fi
if [ ! -d ./backup ]; then mkdir ./backup; fi
backupdir=$(mktemp -dt "backup.XXXXXXXX" --tmpdir=./backup)
# get etcd's node name
etcd_node=`oc get pods -n openshift-etcd -l app=etcd -o=jsonpath='{.items[0].spec.nodeName}'`
View machineset.yaml
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
creationTimestamp: null
labels:
machine.openshift.io/cluster-api-cluster: dmz-nwccb
name: dmz-nwccb-worker
namespace: openshift-machine-api
spec:
replicas: 1