How to Reinstall Kubernetes on Ubuntu Server

Make sure that you have installed Docker

1. Add a Signed Key to Your Server, before running this command make sure curl is installed on your machine

curl -s | sudo apt-key add

2. Add Kubernetes Repository as it is not included in Ubuntu App Repositories

sudo apt-add-repository "deb kubernetes-xenial main"

3. Install Kubernetes Tools you will need to manage the Cluster when it is up and running

sudo apt-get install kubeadm kubelet kubectl

4. Put the Kubernetes Tools on Hold until everything is configured and up and running

sudo apt-mark hold kubeadm kubelet kubectl

5. If you are planning to use Kubernestes Master Node on the Same Server as the Worker Nodes then you will have to disable or add Tolarations to the Pods when configured. Set the Server you are operating on as a master-machine 

sudo hostnamectl set-hostname master-machine

6. Register the Network IP Range to Kubernetes Admin Controller

sudo kubeadm init --pod-network-cidr=FirstDigits.SecondDigits.0.0/16

7. After Step 6 Completes, follow the instruction from Kubernetes Installation to complete other steps needed. The outcome from Step 6 will look like this:

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join YourLocalIPAddress:Port --token [HashToken] \
    --discovery-token-ca-cert-hash [Algorithm]:[TokenHere]

8. Create Pod Communication Network so that Pods can communicate with each other

sudo kubectl apply -f

9. Now that you followed Step 6 up to Step 8, it's time to join the Worker Node (The machine/server you want to pods to be running on) to the Admin Controller (The Admin Controller Oversees every Node that runs the Multiple Different Pods, Pods can run multiple Deployments (Docker Containers) ).
- Pay Attention to Step 6, as the instruction going forward in Step 7,8,9 will significantly come from the output of Step 6. Except for step 8, which you will have to decide which Network Parameter you would want to use. The output shows you the URL to read more about Step 8 Command.

kubeadm join --discovery-token ThisValueComesFromKubernetesAsOutPutFromStep7 --discovery-token-ca-cert-hash sha256:ThisValueComesFromKubernetesAsOutPutFromStep7  ThisValueComesFromKubernetesAsOutPutFromStep7 

[Note] If everything goes well, you will eventually see the outcome that says:

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

[Note] If you want to allow Nodes to be Scheduled on Master-Node Server

kubectl taint nodes --all
  • You should be proud, a lot could have gone wrong, below are troubleshooting notes:

    Error: [ERROR DirAvailable--etc-kubernetes-manifests]: /etc/kubernetes/manifests is not empty
    Solution: sudo rm -r /etc/kubernetes/manifest/

    Error: [ERROR Port-Number]: Port Number is in use
    Solution: systemctl restart kubelet or systemctl stop kublet #to stop the service
    Note: If you need to restart over type: kubeadmn reset #this will reset every configuration you have done on the Server for Kubernetes, this command might cause a lot of headaches because reinstalling Kubernetes might throw Errors because of previous Directories Created.
    Error: If you installed the Certificates from the previous installation, you might get this error:
    "/etc/kubernetes/controller-manager.conf" exists already but has got the wrong CA cert

    Solution: sudo rm -r /etc/kubernetes/
    Error: Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "kubernetes")

    Solution: This error might have happened because you have different certificates in the Kubernetes Admin Config.yaml vs Home/.kube/config to solve this type:
    (1) sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config #when prompted type "yes"
    (2)  sudo chown $(id -u):$(id -g) $HOME/.kube/config

    Then check if Kubernetes Master-Node is running: kubectl cluster-info 
    you should see something like: Kubernetes master is running at https://IP:Port


kubectl Install Kubernetes on Ubuntu 18.04 Technology published

Was this page helpful?

Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
Login to Continue

Community of Software Developers

Welcome, log in to continue reading. It's free and only takes a minute.

© 2020 - ErnesTech - Privacy