Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
docker_advanced_k8s_init [2020/04/20 11:53] – created andonovj | docker_advanced_k8s_init [2020/05/02 14:13] (current) – andonovj | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Overview===== | =====Overview===== | ||
- | The master instance is the main instance which controls the applications or the containers on the cluster. Don't forget: kubernetes consists of at least 1 master and 2 node. In total 2 machines which can run the application. | + | The master instance is the main instance which controls the applications or the containers on the cluster. Don't forget, in our case, kubernetes consists of at least 1 master and 2 node. In total 2 machines which can run the application. |
+ | |||
+ | So let's initialize the cluster from the master instance: | ||
+ | |||
+ | |||
+ | =====Initiliaze the cluster===== | ||
+ | To initialize the cluster, we have to take two factors into consideration: | ||
+ | |||
+ | - Which will be the advertise IP ? | ||
+ | - Which will be the network which we will use for the pods. | ||
+ | |||
+ | The first question is pretty easy. Just use the network which is assigned to your master. In our case, we have 1 master and 2 noides. | ||
+ | So we will assign the advertise IP of the master: | ||
+ | |||
+ | * master - 192.168.50.10 | ||
+ | * node1 - 192.168.50.11 | ||
+ | * node2 - 192.168.50.12 | ||
+ | |||
+ | The second question however, depends on the network which will be used for the pods. In our example I have used calico, because of the reasons listed below.Thus, our pod network by default is: 192.168.0.0/ | ||
+ | |||
+ | So let's see how our commands | ||
+ | |||
+ | < | ||
+ | root@k8s-master: | ||
+ | W0421 09: | ||
+ | [init] Using Kubernetes version: v1.18.2 | ||
+ | [preflight] Running pre-flight checks | ||
+ | [WARNING IsDockerSystemdCheck]: | ||
+ | [preflight] Pulling images required for setting up a Kubernetes cluster | ||
+ | [preflight] This might take a minute or two, depending on the speed of your internet connection | ||
+ | [preflight] You can also perform this action in beforehand using ' | ||
+ | ************************************************************************************************************************** | ||
+ | [kubelet-finalize] Updating "/ | ||
+ | [addons] Applied essential addon: CoreDNS | ||
+ | [addons] Applied essential addon: kube-proxy | ||
+ | |||
+ | 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/ | ||
+ | sudo cp -i / | ||
+ | sudo chown $(id -u):$(id -g) $HOME/ | ||
+ | |||
+ | You should now deploy a pod network to the cluster. | ||
+ | Run " | ||
+ | https:// | ||
+ | |||
+ | Then you can join any number of worker nodes by running the following on each as root: | ||
+ | |||
+ | kubeadm join 192.168.50.10: | ||
+ | --discovery-token-ca-cert-hash sha256: | ||
+ | root@k8s-master: | ||
+ | </ | ||
+ | |||
+ | After that, we have to perform a couple commands from the user, which will be responsible for the kubernetes and won't be root. (P.S. usage of root for applications is STRONGLY DISCOURAGED because of security stuff :) ) | ||
+ | |||
+ | So just transfer it using the instructions above: | ||
+ | |||
+ | < | ||
+ | mkdir -p $HOME/ | ||
+ | sudo cp -i / | ||
+ | sudo chown $(id -u):$(id -g) $HOME/ | ||
+ | </ | ||
+ | |||
+ | Once we have done that, we can check the cluster: | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | </ | ||
+ | |||
+ | Now, you can see that the cluster is saying that the cluster isn't Ready. But what that means, let's see which part isn't ready: | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | NAMESPACE | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | </Code | ||
+ | |||
+ | From this we can see that the CoreDNS isn't ready, meaning our network isn't applied from the steps above: | ||
+ | < | ||
+ | Run " | ||
+ | https:// | ||
+ | </ | ||
+ | |||
+ | ====Configure Calico Pod Network==== | ||
+ | So which podnetwork, we will use. As already mentioned if you are using Kubernetes >1.16, then you cannot use the weave network. Because of that I had to use Calico: | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | configmap/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | customresourcedefinition.apiextensions.k8s.io/ | ||
+ | clusterrole.rbac.authorization.k8s.io/ | ||
+ | clusterrolebinding.rbac.authorization.k8s.io/ | ||
+ | clusterrole.rbac.authorization.k8s.io/ | ||
+ | clusterrolebinding.rbac.authorization.k8s.io/ | ||
+ | daemonset.apps/ | ||
+ | serviceaccount/ | ||
+ | deployment.apps/ | ||
+ | serviceaccount/ | ||
+ | ubuntu@k8s-master: | ||
+ | </ | ||
+ | |||
+ | After that we can check the components again: | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | NAMESPACE | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | </ | ||
+ | |||
+ | |||
+ | We see they are being Initialized as well: " | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | ubuntu@k8s-master: | ||
+ | ubuntu@k8s-master: | ||
+ | NAMESPACE | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | </ | ||
+ | |||
+ | That concludes the initialization of the cluster. In the next section we will discuss how to add new nodes :) | ||
+ | |||
+ | =====Joint to the cluster===== | ||
+ | Be sure that you installed the necessary packages from the introduction section. Once this is done we can add the node to the cluster as follow: | ||
+ | |||
+ | < | ||
+ | root@node-1: | ||
+ | W0421 10: | ||
+ | [preflight] Running pre-flight checks | ||
+ | [WARNING IsDockerSystemdCheck]: | ||
+ | [preflight] Reading configuration from the cluster... | ||
+ | [preflight] FYI: You can look at this config file with ' | ||
+ | [kubelet-start] Downloading configuration for the kubelet from the " | ||
+ | [kubelet-start] Writing kubelet configuration to file "/ | ||
+ | [kubelet-start] Writing kubelet environment file with flags to file "/ | ||
+ | [kubelet-start] Starting the kubelet | ||
+ | [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap... | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Run ' | ||
+ | |||
+ | root@node-1: | ||
+ | </ | ||
+ | |||
+ | As with the master node, it might take sometime until you see the node as Ready and all components running from the Control Panel Machine: | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | node-1 | ||
+ | ubuntu@k8s-master: | ||
+ | ubuntu@k8s-master: | ||
+ | NAMESPACE | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | </ | ||
+ | |||
+ | Please execute that step on all nodes. In the end you should have something like this: | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | node-1 | ||
+ | node-2 | ||
+ | ubuntu@k8s-master: | ||
+ | NAMESPACE | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | </ | ||
+ | |||
+ | ====Assign role to a Node==== | ||
+ | You saw that our nodes have no roles. We have 1 master and that is that :) | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | node-1 | ||
+ | node-2 | ||
+ | </Code | ||
+ | |||
+ | So, how to assign roles to the node. Well, in Kubernetes, we assign labels. Labels are assigned as follows: | ||
+ | |||
+ | < | ||
+ | kubectl label node <node name> node-role.kubernetes.io/< | ||
+ | kubectl label node <node name> node-role.kubernetes.io/< | ||
+ | </ | ||
+ | |||
+ | So let's assign worker to our node-1 and node-2 | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | node/node-1 labeled | ||
+ | ubuntu@k8s-master: | ||
+ | node/node-2 labeled | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | node-1 | ||
+ | node-2 | ||
+ | ubuntu@k8s-master: | ||
+ | </ | ||
+ | |||
+ | Alternatively we can remove a label from a node. So let's remove and add that label again on Node-2: | ||
+ | |||
+ | < | ||
+ | ubuntu@k8s-master: | ||
+ | node/node-2 labeled | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | node-1 | ||
+ | node-2 | ||
+ | ubuntu@k8s-master: | ||
+ | node/node-2 labeled | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | k8s-master | ||
+ | node-1 | ||
+ | node-2 | ||
+ | ubuntu@k8s-master: | ||
+ | </ | ||
- | So let's initialize the cluster |