Kubernetes Setup : Linux

 Kubernetes Environment  Setup

Note : Kubeadm is currently in strong development, hence it is not recommended in production.


  1. sudo apt-get remove docker docker-engine docker.io
  2. sudo apt-get update && sudo apt-get install  -y apt-transport-https  ca-certificates    curl      software-properties-common
  3. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. sudo apt-key fingerprint 0EBFCD88
  5. sudo add-apt-repository  "deb [arch=amd64] https://download.docker.com/linux/ubuntu   $(lsb_release -cs)  stable"
  6. sudo apt-get update && sudo apt-get install docker-ce=17.03.0~ce-0~ubuntu-xenial
  7. cat << EOF > /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
  1. systemctl enable docker && systemctl start docker
           
                                    Kubernetes Installation


  1. apt-get update && apt-get install -y apt-transport-https
  2. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
  3. cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
  1. apt-get update
  2. apt-get install -y kubelet kubeadm kubectl
  3. swapoff -a
  4. kubeadm init --pod-network-cidr=10.244.0.0/16


Below steps will be generated once kubeadm init gets completed


mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config



##########################################################################
Note : A token will be generated similar to below format, this is used to join multiple VM's to kubernetes cluster ###################################################################
kubeadm join --token 408875.a2c451dee603262b 192.168.244.221:6443 --discovery-token-ca-cert-hash sha256:2dd1a79ba8d695486021ede4b357b1d0a5288a59162231c7c732c08c9179f493


Make Sure with the below command to check all services are Up and Running


  1. kubectl taint nodes --all node-role.kubernetes.io/master-
  2. kubectl get pods --all-namespaces


Creating Sample Application


Create  an Deployment ( keeps nodes up and running)  and a pod ( nothing but a collection of container or a single container)
  1. kubectl run webserver --image=nginx
  2. Exposing service
kubectl expose deployment webserver --port 80 --type LoadBalancer  --external-ip=192.168.244.221
  1. kubeadm init pod-network-cidr=10.244.0.0/16 --skip-preflight-checks=true

Create Application with YAML (Recommended)


Ref:

https://kubernetes.io/docs/getting-started-guides/ubuntu/

Comments