2

I am using an Ubuntu 22.04 machine to run and test Kubernetes locally. I need some functionality like Docker-Desktop. I mean it seems both master and worker nodes/machines will be installed by Docker-Desktop on the same machine. But when I try to install Kubernetes and following the instructions like this, at some points it says run the following codes on master node:

sudo hostnamectl set-hostname kubernetes-master

Or run the following comands on the worker node machine:

sudo hostnamectl set-hostname kubernetes-worker

I don't know how to specify master/worker nodes if I have only my local Ubuntu machine?

Or should I run join command after kubeadm init command? Because I can't understand the commands I run in my terminal will be considered as a command for which master or worker machine?

I am a little bit confused about this master/worker nodes or client/server machine stuff while I am just using one machine for both client and server machines.

best_of_man
  • 643
  • 2
  • 15

2 Answers2

1

Prerequisites for installing kubernetes in cluster:

  1. Ubuntu instance with 4 GB RAM - Master Node - (with ports open to all traffic)
  2. Ubuntu instance with at least 2 GB RAM - Worker Node - (with ports open to all traffic)

It means you need to create 3 instances from any cloud provider like Google (GCP), Amazon (AWS), Atlantic.Net Cloud Platform, cloudsigma as per your convenience.

For creating an instance in gcp follow this guide. If you don’t have an account create a new account ,New customers also get $300 in free credits to run, test, and deploy workloads.

After creating instances you will get ips of the instance using them you can ssh into the instance using terminal in your local machine by using the command: ssh root@<ip address>

From there you can follow any guide for installing kubernetes by using worker and master nodes.

example:

sudo hostnamectl set-hostname <host name>

Above should be executed in the ssh of the worker node, similarly you need to execute it into the worker node.

Sai Chandra Gadde
  • 2,242
  • 1
  • 3
  • 15
  • 1
    Thank you, but I just want to install and use `kubernetes` locally! Like what I was doing when I installed `Docker-Desktop` on my Windows machine. – best_of_man Dec 13 '22 at 18:11
1

The hostname does nothing about node roles.

If you do kubeadm init, the node will be a master node (currently called control plane).

This node can also be used as a worker node (currently called just a node), but by default, Pods cannot be scheduled on the control plane node.

You can turn off this restriction by removing its taints with the following command:

kubectl taint nodes --all node-role.kubernetes.io/master-
kubectl taint nodes --all  node-role.kubernetes.io/control-plane-

and then you can use this node as both control-plane and node.

But I guess some small kubernetes like k0s, k3s, and microk8s are better options for your use case rather than kubeadm.

Daigo
  • 815
  • 1
  • 5
  • 16
  • Thank you so much with your help. May you explain more about `Some small kubernetes like k0s, k3s, and microk8s are better options for your use case rather than kubeadm.`? I am very interested to know more about them, also the difference between how they work. Also the difference between them and `Docker-Desktop` or `minikube`. I have searched about them but there are a lot of details and concepts that I can't understand correctly as a new comer! I neead a brief introduction about how all of these work and what are the differences? – best_of_man Dec 14 '22 at 01:07
  • I have also a problem initializing `kubeadm` that I have been searching for that and trying any solution I find for days but none of them worked! – best_of_man Dec 14 '22 at 01:09
  • Also to make sure I understood what you just said in your answer, THERE IS NO PARTICULAR WAY TO SPECIFY I WANT TO RUN THIS COMMAND ON MASTER NODE OR WORKER NODE WHILE YOU ARE USING ONLY 1 MACHINE FOR BOTH MASTER AND WORKER NODES, BUT KUBERNETES WILL UNDERSTAND "WHAT COMMAND SHOULD BE EXECUTED ON WHAT TYPE OF MACHINE AND WILL DO IT AUTOMATICALLY FOR US". I mean we use same terminal to run both master and worker nodes at a time. Did I get that correct? – best_of_man Dec 14 '22 at 01:14
  • For the first question, as StackOverflow is only for programming, I can't answer it here. But at least they're much simpler than kubeadm and easy to use. Regarding the second question, you should search for it, and if the problem persists, ask another question (ServerFault is the best place to ask about it). Third question... yes maybe. You will use a single terminal, and there is only a single server with both master and worker functions. By the way, basically, when you use kubernetes you won't run any commands on the worker. – Daigo Dec 14 '22 at 02:45
  • I tried `kubectl taint nodes --all node-role.kubernetes.io/master-` but got `error: taint "node-role.kubernetes.io/master" not found` – best_of_man Dec 14 '22 at 03:11
  • So you say if I use `microk8s add-node` or `microk8s join 192.168.1.230:25000/92b2db237428470dc4fcfc4ebbd9dc81/2c0cb3284b05` commands after installing `microk8s` on the same machine, it's wrong and I shouldn't do that and I must only use `taint node` commands? – best_of_man Dec 14 '22 at 03:13
  • Hmm, weren't you using `kubeadm` to build local k8s? My answer is for `kubeadm` workload, not microk8s. If you use microk8s, there should be another way that is different from my answer. – Daigo Dec 14 '22 at 04:23
  • Yes, I tried to install microk8s to see if that works? Could you provide a link for that, or could you add that way as well to your answer? – best_of_man Dec 14 '22 at 04:59
  • Sorry I haven't done that, I recommend that you create another post on ServerFault. This issue may be off-topic on SO. – Daigo Dec 14 '22 at 06:38
  • I asked my `kubernetes` questions here and hope you will help me there I can understand it's architecture better: https://serverfault.com/questions/1118050/should-i-run-join-or-taint-after-kubeadm-init – best_of_man Dec 15 '22 at 05:13