How to install Kubernetes and How to add worker-nodes to Kubernetes-Master
Let's consider 1 Kubernetes-Cluster and 2 Worker-Nodes
t2.large t2.microsudo su
yum install docker -y
systemctl enable docker && systemctl start dockercat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kube*
EOFcat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
setenforce 0yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet && systemctl start kubelet<!-- language: lang-html -->vi /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl restart kubeletOnly on the Master Node:
kubeadm init --ignore-preflight-errors allexport KUBECONFIG=/etc/kubernetes/admin.conf after export PATH in .bash_profilels -al
vi .bash_profile<!-- language: lang-html -->export KUBECONFIG=/etc/kubernetes/admin.confOn All Worker nodes :
<kubeadm join command copied from master node>
# kubeadm join 172.31.37.128:6443 --token sttk5b.vco0jw5bkkf1toa4 \
--discovery-token-ca-cert-hash sha256:d77b5f865c1e30b73ea4dd7ea458f79f56da94f9de9c8d7a26b226d94fd0c49eOn the Master Node :
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"<!-- language: lang-html -->kubectl get nodesThat's it :)
The easiest way to start Kubernetes on Amazon Linux AMI (or any other Linux AMI) is to use Microk8s (a lightweight distribution of Kubernetes).
The following steps will help you get started with Kubernetes on EC2 instance:
Install Microk8s on EC2 instance
sudo snap install microk8s --classic
Check the status while Kubernetes starts
microk8s status --wait-ready
Turn on the services you want
microk8s enable dashboard dns registry istio
Start using Kubernetes
microk8s kubectl get all --all-namespaces
Access the Kubernetes dashboard
microk8s dashboard-proxy
microk8s start and microk8s stopThis way you can install a local version of Kubernetes with Microk8s. You can also follow this tutorial for detailed instructions on the above steps.