Skip to content

Instantly share code, notes, and snippets.

@akaron
akaron / Vagrantfile
Created February 21, 2022 06:26
Vagrantfile_alpine312_with_docker_and_mount
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<-SCRIPT
apk add --no-cache docker && rc-update add docker boot && service docker start
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "generic/alpine312"
config.vm.synced_folder "D:\\data", "/data"
# config.vm.synced_folder "D:\\data\\data", "/var/lib/docker" # docker cannot run with use, probably issue of the filesystem format "vboxsf"
#!/usr/bin/env bash
# modified from: https://itnext.io/how-to-cold-start-fast-a-java-service-on-k8s-eks-3a7b4450845d
ns=$1
pod=$2
scheduled=`kubectl -n $ns get pod $pod -o json | jq -r '.status.conditions[] | select(.type=="PodScheduled") | .lastTransitionTime' | sed 's/T/ /g' | tr -d 'Z'`
ready=`kubectl -n $ns get pod $pod -o json | jq -r '.status.conditions[] | select(.type=="Ready") | .lastTransitionTime' | sed 's/T/ /g' | tr -d 'Z'`
scheduled_epoch=`date -u -d "$scheduled" +%s`
echo "${pod} sechedualed at ${scheduled_epoch}"
ready_epoch=`date -u -d "$ready" +%s`
load_seconds=$((ready_epoch-scheduled_epoch))
@akaron
akaron / gist:8adb6cf7a008efd6d4772bf508965f2e
Created November 9, 2021 02:42
elasticsearch 6.2.2 health status examples
# use `kibana -> dev-tools -> console` or curl
# get cluster health
GET _cluster/health
# indices: the health should be green
GET _cat/indices?v
# shard: the state should be "STARTED"
GET _cat/shards?v
@akaron
akaron / patch_redis.sh
Created October 20, 2021 08:24
example: k8s patch script
#!/bin/bash
# get all deployments with name `redis-sentinel-manager` or `redis-cluster-manager`
# and patch these deploy with a nodeSelector with name similar to group-<ns>: <ns>
read -r -d '' tmpl <<'EOF'
kubectl -n i_ns patch deploy i_deploy --type='json' -p='[{"op": "add", "path": "/spec/template/spec/nodeSelector/group-i_ns", "value": "i_ns" }]'
EOF
# redis
ns_deploy=$(kubectl get deploy --all-namespaces|grep -E 'redis-.*-manager' | awk '{printf "%s+%s ", $1,$2}')
@akaron
akaron / log_watcher.service
Created July 22, 2021 08:10
monitor log for keyword and send email
# put this to /etc/systemd/system
[Unit]
Description=watch log events and sendout mail when something happened
[Service]
ExecStart=/root/log_watcher.sh # change the path, and make the file executable
[Install]
WantedBy=multi-user.target
@akaron
akaron / k8s_prepare_for_ubuntu.sh
Last active April 22, 2021 03:02
ubuntu1804_prepare_k8s
#!/bin/bash
# For ubuntu-18.04.5-live-server-amd64.iso
set -ex
# set-up repositories
apt-get update
apt-get upgrade -y
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release ntp nfs-common
# add nfs-common if use nfs-provisioner
@akaron
akaron / ansible.yaml
Last active January 6, 2021 04:13
Use ansible to install ansible in another ubuntu machine (such as a Vagrant provisioned VM)
---
- hosts: master1
become: yes
vars:
- user_name: vagrant
tasks:
- name: install python virtualenv
block:
- name: install python virtualenv
apt:
@akaron
akaron / jenkins
Created November 10, 2020 15:36
nginx reverse proxy for jenkins with SSL enabled
# nginx configuration for a reverse proxy for an existing jenkins, with SSL enabled
# modified from https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-nginx/
# Steps:
# 0. confirm jenkins is running; confirm a domain name is properly configured (apicat.xyz in this example)
# - for instance, add the domain in aws route 53 or DO domain
# - then add the NS record (aws or DO or others) back to where you register the domain (namecheap/godaddy/...)
# - this may take some time (at least several minutes)
# 1. Put these config to nginx configuration (such as a new file in /etc/nginx/nginx-sites-enabled or append to /etc/nginx/nginx.conf)
# 2. update config if necessary: jenkins ip and port, root directories, server_name.
# - run `sudo nginx -t` to verify the file
@akaron
akaron / Vagrantfile
Created October 28, 2020 14:11
use vagrant and k3s to deploy a kubernetes cluster in local VM
# run a kubernetes cluster in local VM using vagrant + k3s
# require: Virtualbox, vagrant
# steps:
# * in the folder contain this `Vagrantfile`, run `vagrant up` and wait a bit for provisioning.
# Once done, `vagrant ssh master` into the node and start using the k8s cluster,
# such as `kubectl get nodes`, `kubectl get pods -A`, `kubectl get componentstatus`,
# or `kubectl run busybox --image=busybox:1.28 --rm --restart=Never -it -- nslookup kubernetes`
# * To clean up, logout these nodes, then run `vagrant destroy` to destroy the VMs.
# - next time run `vagrant up` again to provision again
# - or run `vagrant halt` to halt these VMs, and bring them back to the same state
@akaron
akaron / Vagrantfile
Created August 6, 2020 10:17
an example Vagrant file which uses ansible to provision
# -*- mode: ruby -*-
# vi: set ft=ruby :
# ENV["LC_ALL"] = "en_US.UTF-8"
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox" do |v|
v.name = "tst_terraform_packer"