Install and Deploy Kubernetes on Ubuntu 18.04 LTS
- Install Docker on all nodes:
sudo apt install docker.io- Check docker install:
docker --version- Enable Docker on all nodes:
sudo systemctl enable docker- Add the Kubernetes signing key on all nodes:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add- Add Kubernetes Repository on all nodes:
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"- Install Kubeadm:
sudo apt install kubeadm- Check Kubeadm installation:
kubeadm version- Disable swap memory on all nodes:
sudo swapoff -aand eliminate any occurrence of swap in /etc/fstab using
sudo nano /etc/fstab- Initialize Kubernetes on the master node:
sudo kubeadm init- Run the following:
mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config- On the remaining nodes run the command starts with:
kubeadm join 192.168.100.6:6443 --token ...You can find the full command in the results of step 9
- Create pod network through the master node:
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"- Check the cluster works correctly:
kubectl get nodeson master node
Generate admin.key and admin.csr using openssl
openssl genrsa -out admin.key 2048
openssl req -new -key admin.key -out admin.csr -subj "/O=system:masters/CN=kubernetes-admin"Now create CSR in kubernetes using above openssl admin.csr
cat <<EOF | kubectl create -f -
apiVersion: certificates.k8s.io/v1beta1
kind: CertificateSigningRequest
metadata:
name: admin_csr
spec:
groups:
- system:authenticated
request: $(cat admin.csr | base64 | tr -d '\n')
usages:
- digital signature
- key encipherment
- client auth
EOFNow approve the CSR generated using
kubectl certificate approve admin_csrNow extract the admin.crt from approved CSR
kubectl get csr admin_csr -o jsonpath='{.status.certificate}' | base64 -d > admin.crtNow change the current user and context to use the new admin key and certificates
kubectl config set-credentials kubernetes-admin --client-certificate=/home/centos/certs/admin.crt --client-key=/home/centos/certs/admin.key
kubectl config set-context kubernetes-admin@kubernetes --cluster=kubernetes --user=kubernetes-admin