Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docker_advanced_k8s_init [2020/04/20 11:55] – 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: | So let's initialize the cluster from the master instance: | ||
- | =====Initialize | + | =====Initiliaze |
- | <Code:shell|Initliaze | + | To initialize the cluster, we have to take two factors into consideration: |
- | root@k8s-master: | + | |
- | W0420 11:51:44.473212 | + | - 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 | ||
+ | |||
+ | <Code:none|Initialize | ||
+ | root@k8s-master: | ||
+ | W0421 09:20:50.597038 | ||
[init] Using Kubernetes version: v1.18.2 | [init] Using Kubernetes version: v1.18.2 | ||
[preflight] Running pre-flight checks | [preflight] Running pre-flight checks | ||
Line 15: | Line 31: | ||
[preflight] This might take a minute or two, depending on the speed of your internet connection | [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 ' | [preflight] You can also perform this action in beforehand using ' | ||
- | [kubelet-start] Writing kubelet environment file with flags to file "/ | + | ************************************************************************************************************************** |
- | [kubelet-start] Writing kubelet configuration to file "/ | + | |
- | [kubelet-start] Starting the kubelet | + | |
- | [certs] Using certificateDir folder "/ | + | |
- | [certs] Generating " | + | |
- | [certs] Generating " | + | |
- | [certs] apiserver serving cert is signed for DNS names [k8s-master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.0.2.15] | + | |
- | [certs] Generating " | + | |
- | [certs] Generating " | + | |
- | [certs] Generating " | + | |
- | [certs] Generating " | + | |
- | [certs] Generating " | + | |
- | [certs] etcd/server serving cert is signed for DNS names [k8s-master localhost] and IPs [10.0.2.15 127.0.0.1 ::1] | + | |
- | [certs] Generating " | + | |
- | [certs] etcd/peer serving cert is signed for DNS names [k8s-master localhost] and IPs [10.0.2.15 127.0.0.1 ::1] | + | |
- | [certs] Generating " | + | |
- | [certs] Generating " | + | |
- | [certs] Generating " | + | |
- | [kubeconfig] Using kubeconfig folder "/ | + | |
- | [kubeconfig] Writing " | + | |
- | [kubeconfig] Writing " | + | |
- | [kubeconfig] Writing " | + | |
- | [kubeconfig] Writing " | + | |
- | [control-plane] Using manifest folder "/ | + | |
- | [control-plane] Creating static Pod manifest for " | + | |
- | [control-plane] Creating static Pod manifest for " | + | |
- | W0420 11: | + | |
- | [control-plane] Creating static Pod manifest for " | + | |
- | W0420 11: | + | |
- | [etcd] Creating static Pod manifest for local etcd in "/ | + | |
- | [wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/ | + | |
- | [apiclient] All control plane components are healthy after 33.018814 seconds | + | |
- | [upload-config] Storing the configuration used in ConfigMap " | + | |
- | [kubelet] Creating a ConfigMap " | + | |
- | [upload-certs] Skipping phase. Please see --upload-certs | + | |
- | [mark-control-plane] Marking the node k8s-master as control-plane by adding the label " | + | |
- | [mark-control-plane] Marking the node k8s-master as control-plane by adding the taints [node-role.kubernetes.io/ | + | |
- | [bootstrap-token] Using token: q331e1.bivia9jev4bvugpg | + | |
- | [bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles | + | |
- | [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes | + | |
- | [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials | + | |
- | [bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token | + | |
- | [bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster | + | |
- | [bootstrap-token] Creating the " | + | |
[kubelet-finalize] Updating "/ | [kubelet-finalize] Updating "/ | ||
[addons] Applied essential addon: CoreDNS | [addons] Applied essential addon: CoreDNS | ||
Line 77: | Line 50: | ||
Then you can join any number of worker nodes by running the following on each as root: | Then you can join any number of worker nodes by running the following on each as root: | ||
- | kubeadm join 10.0.2.15:6443 --token | + | kubeadm join 192.168.50.10:6443 --token |
- | --discovery-token-ca-cert-hash sha256:5a1ac41454c7121422e6fb974e61533477cdbfcdc002adc17eb34aaed320e7d1 | + | --discovery-token-ca-cert-hash sha256:8c7874be67b9670c52a729b7a26bdefb4b55f5a49402624c0d262c0253732228 |
root@k8s-master: | root@k8s-master: | ||
</ | </ | ||
- | The last command, given to us, is the join command | + | 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 |
+ | |||
+ | 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 | ||
+ | < | ||
+ | Run " | ||
+ | https:// | ||
+ | </ | ||
+ | |||
+ | ====Configure Calico Pod Network==== | ||
+ | So which podnetwork, | ||
+ | |||
+ | < | ||
+ | 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 | ||
+ | |||
+ | =====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: | ||
+ | </ |