Skip to content

Instantly share code, notes, and snippets.

@krokwen
Last active September 5, 2018 06:45
Show Gist options
  • Save krokwen/35b77487f3ea8c093332ee15dcef109a to your computer and use it in GitHub Desktop.
Save krokwen/35b77487f3ea8c093332ee15dcef109a to your computer and use it in GitHub Desktop.
kubernetes setup
# ubuntu 16.04 used on all nodes
# all your nodes must have static ip in local network
# all your nodes must no have enabled swap partition
# perform this on all nodes:
apt update && apt upgrade -y
apt install -y docker.io
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
apt update && apt install -y kubelet kubeadm kubectl
# run this on your master:
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=<master static ip>
# save last ~10 strings of otput with command for joining slave nodes
mkdir $HOME/.kube
cp -i /etc/kubernetes/admin.conf .kube/config
# enable bridging
echo "net.bridge.bridge-nf-call-iptables=1" >> /etc/sysctl.conf
sysctl -p
# apply weave net addon
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
# on slave node run saved previously command "kubeadm join...."
# dashboard
# on your local machine install kubectl
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo cp kubectl /usr/local/bin/ && rm kubectl
# copy ~/.kube/config from master to your local machine with same path and name
# create somwhere directory for your yml files, for example ~/myKubeYmls
# check connection with this command
kubectl cluster-info
# apply dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
# run proxy on master node
kubectl proxy --accept-hosts='^.*$' --address='{your_server_ip}' &
# back on your local machine
cd ~/myKubeYmls
# create ~/myKubeYmls/dashboard-admin.yml with this contents:
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
#EOF
# run this to create role binding resource
kubectl create -f dashboard-admin.yml
# now you can access dashboard in your browser http://{your kubernetes master hostname}:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment