-
-
Save andrey-zh/1b5f30e9cf61bdf64b04cb830151f9f4 to your computer and use it in GitHub Desktop.
Install Kubernetes
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 | |
# curl https://gist.githubusercontent.com/jeremyje/14e26148909734ebe1d6395cc8b0e156/raw/dashboard.sh | bash | |
# https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ | |
# https://github.com/kubernetes/dashboard | |
bash -c "cat >> dashboard.yaml" << EOF | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: kubernetes-dashboard | |
namespace: kubernetes-dashboard | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: kubernetes-dashboard | |
namespace: kubernetes-dashboard | |
roleRef: | |
apiGroup: rbac.authorization.k8s.io | |
kind: ClusterRole | |
name: cluster-admin | |
subjects: | |
- kind: ServiceAccount | |
name: kubernetes-dashboard | |
namespace: kubernetes-dashboard | |
EOF | |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.1/aio/deploy/recommended.yaml | |
kubectl apply -f dashboard.yaml | |
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}') |
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 | |
# curl https://gist.githubusercontent.com/jeremyje/14e26148909734ebe1d6395cc8b0e156/raw/install.sh | bash | |
# Based on https://docs.docker.com/install/linux/docker-ce/debian/ | |
function InstallForDebian { | |
sudo apt-get update | |
sudo apt-get -y remove docker docker-engine docker.io | |
sudo apt-get -y install \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg2 \ | |
software-properties-common | |
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - | |
sudo apt-key fingerprint 0EBFCD88 | |
sudo add-apt-repository \ | |
"deb [arch=amd64] https://download.docker.com/linux/debian \ | |
$(lsb_release -cs) \ | |
stable" | |
sudo apt-get update | |
sudo apt-get install -y docker-ce | |
apt-cache madison docker-ce | |
# https://docs.docker.com/install/linux/linux-postinstall/ | |
sudo groupadd docker | |
sudo usermod -aG docker $USER | |
echo Logout to use docker without sudo. | |
} | |
# Based on https://docs.docker.com/install/linux/docker-ce/ubuntu/ | |
function InstallForUbuntu { | |
sudo apt-get update | |
sudo apt-get -y remove docker docker-engine docker.io | |
sudo apt-get -y install \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo apt-key fingerprint 0EBFCD88 | |
sudo add-apt-repository \ | |
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) \ | |
stable" | |
sudo apt-get update | |
sudo apt-get install -y docker-ce | |
apt-cache madison docker-ce | |
# https://docs.docker.com/install/linux/linux-postinstall/ | |
sudo groupadd docker | |
sudo usermod -aG docker $USER | |
echo Logout to use docker without sudo. | |
} | |
# Installing kubeadm, kubelet and kubectl | |
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl | |
function InstallKubeadm { | |
# Setup Kubernetes APT repository | |
sudo apt-get update && sudo apt-get install -y apt-transport-https curl | |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - | |
sudo bash -c "cat >> /etc/apt/sources.list.d/kubernetes.list" << EOF | |
deb https://apt.kubernetes.io/ kubernetes-xenial main | |
EOF | |
# Install kubeadm and kubectl | |
sudo apt-get update | |
sudo apt-get install -y kubelet kubeadm kubectl | |
sudo apt-mark hold kubelet kubeadm kubectl | |
} | |
# Ensure iptables tooling does not use the nftables backend | |
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#ensure-iptables-tooling-does-not-use-the-nftables-backend | |
function IptablesOnLegacyBackend { | |
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy | |
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy | |
sudo update-alternatives --set arptables /usr/sbin/arptables-legacy | |
sudo update-alternatives --set ebtables /usr/sbin/ebtables-legacy | |
} | |
function ConfigureCgroupDriver { | |
sudo bash -c "cat >> /etc/docker/daemon.json" << EOF | |
{ | |
"exec-opts": ["native.cgroupdriver=systemd"], | |
"log-driver": "json-file", | |
"log-opts": { | |
"max-size": "100m" | |
}, | |
"storage-driver": "overlay2" | |
} | |
EOF | |
sudo mkdir -p /etc/systemd/system/docker.service.d | |
sudo systemctl daemon-reload | |
sudo systemctl restart docker | |
} | |
function InstallKubernetes { | |
# Verify the MAC address and product_uuid are unique for every node | |
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#verify-the-mac-address-and-product-uuid-are-unique-for-every-node | |
echo MAC Address | |
ip link | |
echo product_uuid | |
sudo cat /sys/class/dmi/id/product_uuid | |
# Instructions: https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/ | |
# Update APT repository cache and install ifconfig. | |
sudo apt update | |
sudo apt -y install net-tools | |
IptablesOnLegacyBackend | |
InstallKubeadm | |
# Cache all the vanilla Kubernetes docker images. | |
sudo kubeadm config images pull | |
# Disable swap partition. | |
sudo swapoff -a | |
sudo sed -i '/ swap / s/^/#/' /etc/fstab | |
} | |
function PostInstallKubernetes { | |
echo "Kubernetes is installed." | |
echo "For kubelets (Run this on master to get join command):" | |
echo " kubeadm token create --print-join-command" | |
echo "For kube master:" | |
echo "curl https://gist.githubusercontent.com/jeremyje/14e26148909734ebe1d6395cc8b0e156/raw/master.sh | bash" | |
} | |
function InstallDocker { | |
if [[ "$(lsb_release -si)" == "Debian" ]]; then | |
InstallForDebian | |
elif [[ "$(lsb_release -si)" == "Ubuntu" ]]; then | |
InstallForUbuntu | |
else | |
echo "Not supported." | |
fi | |
} | |
InstallDocker | |
ConfigureCgroupDriver | |
InstallKubernetes | |
PostInstallKubernetes |
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 | |
# curl https://gist.githubusercontent.com/jeremyje/14e26148909734ebe1d6395cc8b0e156/raw/master.sh | bash | |
function WaitForKubectl { | |
n=0 | |
until [ $n -ge 5 ] | |
do | |
command && kubectl get nodes | |
n=$[$n+1] | |
sleep 5 | |
done | |
} | |
function InstallWeaveNet { | |
echo "Install WeaveNet" | |
sudo sysctl net.bridge.bridge-nf-call-iptables=1 | |
#sudo kubeadm init --pod-network-cidr=10.244.0.0/16 | |
sudo kubeadm init --pod-network-cidr=192.168.86.0/24 | |
echo "Waiting for network (10s)..." | |
WaitForKubectl | |
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#pod-network | |
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" | |
} | |
function InstallFlannel { | |
echo "Install Flannel" | |
sudo sysctl net.bridge.bridge-nf-call-iptables=1 | |
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 | |
echo "Waiting for network (10s)..." | |
WaitForKubectl | |
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#pod-network | |
#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml | |
#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/4ff77dc7c35851913587f7daccf25d754e77aa65/Documentation/kube-flannel.yml | |
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml | |
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml | |
#echo "Opening UDP ports for Flannel Network Fabric" | |
sudo iptables -A INPUT -p udp --dport 8285 -j ACCEPT | |
sudo iptables -A INPUT -p udp --dport 8472 -j ACCEPT | |
} | |
function InstallPostFlannel { | |
#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml | |
#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/4ff77dc7c35851913587f7daccf25d754e77aa65/Documentation/kube-flannel.yml | |
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml | |
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml | |
} | |
function InstallCalico { | |
echo "Install Calico Network Fabric" | |
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml | |
sudo kubeadm init --pod-network-cidr=192.168.86.0/24 | |
} | |
function InstallKubeRouter { | |
echo "Install KubeRouter Fabric" | |
sudo kubeadm init --pod-network-cidr=192.168.86.0/24 | |
} | |
function Prereq { | |
sudo swapoff -a | |
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf | |
net.bridge.bridge-nf-call-ip6tables = 1 | |
net.bridge.bridge-nf-call-iptables = 1 | |
EOF | |
sudo sysctl --system | |
} | |
Prereq | |
InstallFlannel | |
#InstallWeaveNet | |
#InstallKubeRouter | |
#InstallCalico | |
mkdir -p $HOME/.kube | |
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config | |
sudo chown $(id -u):$(id -g) $HOME/.kube/config | |
InstallPostFlannel | |
echo "Run on all kubelets" | |
kubeadm token create --print-join-command | |
echo "Enable Pods on Master" | |
echo "kubectl taint nodes --all node-role.kubernetes.io/master-" |
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 | |
# curl https://gist.githubusercontent.com/jeremyje/14e26148909734ebe1d6395cc8b0e156/raw/uninstall.sh | bash | |
# https://medium.com/@meysam1369/kubernetes-completely-uninstall-3f2a83dd985d | |
function UnregisterNodes { | |
for NODE_NAME in $(kubectl get nodes -o jsonpath="{.items[*].metadata.name}") | |
do | |
kubectl drain ${NODE_NAME} --delete-local-data --force --ignore-daemonsets | |
kubectl delete node ${NODE_NAME} | |
done | |
} | |
function UninstallKubernetes { | |
kubeadm reset | |
sudo apt-get -y -qq --allow-change-held-packages purge kubeadm kubectl kubelet kubernetes-cni kube* | |
sudo apt-get autoremove | |
sudo rm -rf ~/.kube | |
} | |
UnregisterNodes | |
UninstallKubernetes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment