Skip to content

Instantly share code, notes, and snippets.

@canhnt
canhnt / git-delete-local-tag.sh
Created August 9, 2017 09:11
Delete local tags that do not exist in remote
git fetch --prune origin "+refs/tags/*:refs/tags/*"
@canhnt
canhnt / delete-evicted-pods.sh
Last active June 8, 2018 07:44
Delete all evicted pods
kubectl get pod --all-namespaces | grep Evicted | grep 10d | awk '{print $1" " $2}' | xargs -n2 sh -c 'kubectl delete pod $2 -n $1' sh
@canhnt
canhnt / gen-cert-k8s.sh
Created June 14, 2018 09:05
Create x509 cert for k8s
openssl req -new -key cngo.key -out cngo-csr.pem -subj "/CN=cngo/O=app1/O=infra-team"
openssl x509 -req -in cngo-csr.pem -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out cngo.crt -days 730
@canhnt
canhnt / aws-s3-upload.sh
Created July 9, 2018 09:20
Upload files to Minio server using AWS-CLI
export AWS_CA_BUNDLE=$path_private_ca_cert
aws --endpoint-url https://$minioserver s3 cp $filename s3://$bucketname
@canhnt
canhnt / clean-lv.sh
Last active August 14, 2018 07:23
Clean invalid LVs that exist in physical (via lvscan) but not managed by gluster
#!/usr/bin/env bash
# Find invalid LVs that exist in physical (via lvscan) but not managed by gluster
vgs=$1
host_address='10.165.210.xxx'
valid_lvs=$(gluster volume info | grep $vgs | grep ${host_address} | sed -e 's/.*brick_\(.[a-z0-9]*\)\/brick/\1/')
all_lvs=$(lvscan | grep $vgs | grep 'brick_' | awk -F'brick_' '{ print substr($2,0,32)}')
@canhnt
canhnt / install-ingress.sh
Created August 15, 2018 19:02
Install ingress-nginx
kubectl create -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
@canhnt
canhnt / etcd-defrag.sh
Created September 28, 2018 08:55
Compact and defrag etcd cluster
# Ref https://github.com/etcd-io/etcd/blob/master/Documentation/op-guide/maintenance.md#space-quota
export ETCDCTL_API=3
etcdctl endpoint status --write-out="json"
etcdctl endpoint status --write-out="table"
etcdctl compact $rev
etcdctl defrag
etcdctl endpoint status --write-out="table"
etcdctl alarm list
@canhnt
canhnt / rancher-incident.md
Last active December 20, 2018 21:13
Rancher incident checks

Check numbers of templatecontent custom resource objects in the etcd DB:

etcdctl get  /registry/management.cattle.io/templatecontents --keys-only --prefix | sed '/^\s*$/d' | wc -l

A bug in Rancher prior v2.0.8 and v2.1.0 added a lot of html files in templatecontent objects, which fills up etcd db and may cause K8s master nodes unavailable.

Delete all templatecontent custom resource objects:

etcdctl del /registry/management.cattle.io/templatecontents/ --prefix
@canhnt
canhnt / rancher.md
Last active June 19, 2019 15:58
Rancher cmds

Get current cluster.yaml

kc get cm cluster-state -n kube-system -o jsonpath='{.data.cluster-state}'

Get user-addon settings:

kc get cm  -n kube-system rke-user-addon -o jsonpath='{.data}'
@canhnt
canhnt / gluster-management.md
Last active October 25, 2018 20:55
Gluster management

Check free storage in gluster nodes

for i in $(seq 1 9); do node="829k8xlstorage$i.company.org"; echo "$node checking:"; ssh $node 'df -h'; done 2>/dev/null | grep -E '829k8xlstorage|centos-root'

If any node free is lower than 18%, delete logs:

rm -f /var/log/glusterfs/gluster*
rm -f /var/log/glusterfs/bricks/*