This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # In terraform, the attribute of autoscaling group does not contain detail information of EC2 instances, | |
| # i.e., cannot get the ip of instances for further usage (such as ansible). Of course it's better to make | |
| # it no need to know the ip by using tools such as user-data of EC2 instance (for bootstrap) and LB and | |
| # route 53. | |
| # | |
| # In case still want to know the ip addresses, one can use `data "aws_instances"` which | |
| # `depends_on = [aws_autoscaling_group.name]`, then use tags to get the information of instances. | |
| # ref: https://github.com/terraform-providers/terraform-provider-aws/issues/511#issuecomment-447934405 | |
| provider "aws" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - hosts: master1 | |
| become: yes | |
| vars: | |
| - user_name: vagrant | |
| tasks: | |
| - name: install python virtualenv | |
| block: | |
| - name: install python virtualenv | |
| apt: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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)) |