Skip to content

Instantly share code, notes, and snippets.

View k8scat's full-sized avatar
:dependabot:
I may be slow to respond.

K8sCat k8scat

:dependabot:
I may be slow to respond.
View GitHub Profile
@k8scat
k8scat / backup_volume.sh
Last active May 8, 2021 02:36
Backup data from a volume.
#!/bin/sh
#
# Backup data from a volume.
# Maintainer: k8scat@gmail.com
data_volume=$1
data_dir=$2
if [[ "${data_volume}" = "" || "${data_dir}" = "" ]]; then
echo "usage: $0 <data_volume> <data_dir>"
exit 1
@k8scat
k8scat / install_git.sh
Last active June 13, 2021 17:35
Install git from source code on CentOS 7.
#!/bin/bash
#
# Install git from source code on CentOS 7, refer to https://github.com/git/git/blob/master/INSTALL
set -e
# Get version from https://github.com/git/git/releases, for example: 2.29.2
version=$1
if [[ -z "${version}" ]]; then
echo "usage: $0 <version, 2.29.2> [profile]"
exit 1
@k8scat
k8scat / install_python.sh
Last active May 7, 2021 04:00
Install python3 from source code on CentOS 7.
#!/bin/bash
#
# Install python3 from source code on CentOS 7
# Maintainer: K8sCat <k8scat@gmail.com>
set -e
if [[ $(id -u) -ne 0 ]]; then
echo "require root"
exit 1
fi
@k8scat
k8scat / logfilter.go
Last active May 6, 2021 10:44
Filter content by date range or read only last N lines of a file.
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
"os"
"regexp"
@k8scat
k8scat / watch.sh
Last active May 4, 2021 19:11
Play `watch` in a shell script
#!/bin/sh
# while :; do clear; your_command; sleep 2; done
# usage: watch.sh "<your_command>" "<sleep_duration>"
d=${2:-2}
while :; do
clear
date
$1
sleep ${d}
@k8scat
k8scat / check_ssl.py
Created April 30, 2021 03:30
Check ssl expire time
# Maintainer: k8scat@gmail.com
import sys
import time
from datetime import datetime
import ssl
import socket
def get_ssl_info(domain, port=443):
@k8scat
k8scat / format-time.js
Created April 29, 2021 04:31
Format time from timestamp
export const formatTime = (timestamp) => {
const date = new Date(timestamp);
const YY = date.getFullYear();
const MM = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
const DD = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
const hh = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
const mm = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
const ss = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds();
return `${YY}-${MM}-${DD} ${hh}:${mm}:${ss}`;
};
@k8scat
k8scat / pull_k8s_images.sh
Created April 18, 2021 15:12
Pull K8S images - v1.21.0
#!/bin/bash
#
# Pull K8S images
# Version: 1.21.0
# Maintainer: k8scat@gmail.com
set -e
# Pull images from aliyun registry
kubeadm config images list | sed -e 's/^/docker pull /g' -e 's#k8s.gcr.io#registry.cn-shenzhen.aliyuncs.com/k8scat#g' -e 's#/coredns/coredns#/coredns#g' | sh -x
@k8scat
k8scat / install_kubeadm_kubelet_kubectl.sh
Last active April 18, 2021 15:07
Install kubeadm, kubelet and kubectl
#!/bin/bash
#
# Install kubeadm, kubelet and kubectl
# Maintainer: k8scat@gmail.com
set -e
# 更新 apt 包索引并安装使用 Kubernetes apt 仓库所需要的包
apt-get update -y
apt-get install -y apt-transport-https ca-certificates curl
@k8scat
k8scat / install_python3.8_ubuntu16.sh
Last active April 17, 2021 16:54
Install Python3.8 on Ubuntu 16
#!/bin/bash
#
# Install Python3.8 and pip on Ubuntu 16
# Maintainer: k8scat@gmail.com
set -e
add-apt-repository -y ppa:deadsnakes/ppa
apt-get update -y
apt-get install -y python3.8 python3.8-distutils
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py