Skip to content

Instantly share code, notes, and snippets.

@myclau
Last active November 6, 2018 11:39
Show Gist options
  • Save myclau/4baf888a63d457c6e8deff86adb5762d to your computer and use it in GitHub Desktop.
Save myclau/4baf888a63d457c6e8deff86adb5762d to your computer and use it in GitHub Desktop.
Rancher 2.0 related script
#!/bin/bash
rke etcd snapshot-save --name SNAPSHOT$(date +"%Y_%m_%d_%k_%M_%S").db --config cluster_default_ingress.yml
nodes:
- address: <node1 address>
user: <account name>
role:
- controlplane
- etcd
- worker
hostname_override: kmaster01
- address: <node address>
user: <account name>
role:
- worker
hostname_override: knode01
# If set to true, RKE will not fail when unsupported Docker version are found
ignore_docker_version: true
# Cluster level SSH private key
# Used if no ssh information is set for the node
ssh_key_path: ./keys/rancher_rsa
# Set the name of the Kubernetes cluster
cluster_name: test-sandbox
services:
etcd:
snapshot: true
creation: 6h
retention: 24h
extra_args:
election-timeout: "5000"
heartbeat-interval: "500"
mkdir ~/nginx
cd ~/nginx
docker run -p 1080:80 -p 10443:443 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx
#!/bin/bash
nodes=(
"<account>@<host 1>"
"<account>@<host 2>"
)
#!/bin/bash
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
#check packer version for modify below docker-ce install package version
yum list docker-ce --showduplicates | sort -r
sudo yum -y install docker-ce-18.06.1.ce
#since rancher not support 18.06
#sudo yum install -y --setopt=obsoletes=0 \
# docker-ce-17.03.1.ce-1.el7.centos \
# docker-ce-selinux-17.03.1.ce-1.el7.centos
sudo systemctl start docker
sudo usermod -aG docker $(whoami)
echo 'please logout before you use docker'
#!/bin/bash
cd ~
wget https://github.com/rancher/rke/releases/download/v0.1.11/rke_linux-amd64 && chmod +x rke_linux-amd64
sudo mv rke_linux-amd64 /usr/local/bin/rke
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.11.0-linux-amd64.tar.gz
tar -zxvf helm-v2.11.0-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/helm
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
#!/bin/bash
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install openssh-server -y
#Docker
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get install -y docker-ce
sudo usermod -aG docker $(whoami)
echo please logout before you use docker
#!/bin/bash
sudo apt-get update
#sudo apt-get upgrade
sudo apt-get install openssh-server -y
#Docker
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get install -y docker-ce
sudo usermod -aG docker $(whoami)
echo please logout before you use docker
#!/bin/bash
[ "$1" == "$null" ] && exit
rke etcd snapshot-restore --name $1 --config cluster_default_ingress.yml
#need up again
rke up --config cluster_default_ingress.yml
#!/bin/bash
rke up --config ./cluster_default_ingress.yml
export KUBECONFIG=$(pwd)/kube_config_cluster_default_ingress.yml
kubectl -n kube-system create serviceaccount tiller
kubectl create clusterrolebinding tiller \
--clusterrole cluster-admin \
--serviceaccount=kube-system:tiller
helm init --service-account tiller
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm install stable/cert-manager --name cert-manager --namespace kube-system
helm install rancher-stable/rancher --name rancher --namespace cattle-system --set hostname=<node1 address>
#!/bin/bash
mkdir -p keys
cd keys
ssh-keygen -t rsa -b 4096 -N '' -f rancher_rsa
cat rancher_rsa
cat rancher_rsa.pub
. ../nodeslist.sh
for ((i = 0; i < ${#nodes[@]}; ++i)); do
ssh-copy-id -i rancher_rsa.pub ${nodes[$i]}
done
#!/bin/bash
export KUBECONFIG=$(pwd)/kube_config_cluster_default_ingress.yml
helm init --upgrade --service-account tiller
helm repo update
helm get values rancher
helm upgrade rancher rancher-stable/rancher --set hostname=<node1 address>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment