Quick Installtion bash script with dashboard Print

  • 49

#!/bin/bash

#install updates and install deps

apt-get update && apt-get -my upgrade
swapoff -a
cat /etc/fstab |grep -v swap > /tmp/fs && mv /tmp/fs /etc/fstab
apt-get -my install net-tools ebtables ethtool apt-transport-https ca-certificates curl software-properties-common gnupg2 git

#Install docker
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -add-apt-repository \

"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
apt update
apt-get install -my docker-ce
curl -L https://raw.githubusercontent.com/docker/compose/1.19.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
curl -L https://raw.githubusercontent.com/docker/machine/v0.13.0/contrib/completion/bash/docker-machine.bash -o /etc/bash_completion.d/docker-machine

#Instaall kubernetes
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 /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt install -y kubelet kubeadm kubectl

#Only for master
kubeadm init --pod-network-cidr=192.168.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://docs.projectcalico.org/v2.6/getting-started/kubernetes/installation/hosted/kubeadm/1.6/calico.yaml
kubectl get pods --all-namespaces
kubectl taint nodes --all node-role.kubernetes.io/master-

#Install dashboard
git clone https://github.com/kubernetes/heapster.git
cd heapster
kubectl create -f deploy/kube-config/influxdb/
kubectl create -f deploy/kube-config/rbac/heapster-rbac.yaml
cd ../
mkdir dashboard
cd dashboard

cat <<'EOF' >> admin.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
labels:
k8s-app: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kube-system

---

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system

---

apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system

EOF

#Apply admin rbac
kubectl apply -f admin.yaml

#Get Token
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

cd /usr/local/bin 
curl -O -L https://github.com/projectcalico/calicoctl/releases/download/ 
v2.0.0/calicoctl
chmod +x calicoctl 
mkdir /etc/calico/ 

cat <<'EOF'>> /etc/calico/calicoctl.cfg
apiVersion: projectcalico.org/v3 
kind: CalicoAPIConfig 
metadata: 
spec: 
datastoreType: "kubernetes" 
kubeconfig: "/root/.kube/config" 

EOF 

#A common problem on Linux systems is running out of space in the conntrack table
sysctl -w net.netfilter.nf_conntrack_max=1000000 
echo "net.netfilter.nf_conntrack_max=1000000" >> /etc/sysctl.conf


Was this answer helpful?

« Back