{"id":1698,"date":"2018-10-23T12:31:40","date_gmt":"2018-10-23T09:31:40","guid":{"rendered":"https:\/\/artem.services\/?p=122"},"modified":"2020-03-15T20:58:21","modified_gmt":"2020-03-15T17:58:21","slug":"1698","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1698&lang=en","title":{"rendered":"Kubernetes &#8212; Installing and creating a cluster"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-full wp-image-149 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo.png\" alt=\"\" width=\"844\" height=\"217\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo.png 844w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo-300x77.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo-768x197.png 768w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><\/p>\n<p>First you need to <a href=\"https:\/\/artem.services\/?p=1665&amp;lang=en\" target=\"_blank\" rel=\"noopener noreferrer\">install Docker<\/a>.<\/p>\n<p>For <strong>Kubernetes<\/strong> to work correctly, you must disable <strong>SWAP<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nswapoff -a\r\n<\/pre>\n<p>Also check delete it with <strong>fstab<\/strong><\/p>\n<p>Add <strong>Kubernetes<\/strong> repository and install<\/p>\n<h3>Ubuntu:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\napt update &amp;&amp; apt install -y apt-transport-https\r\ncurl -s https:\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | apt-key add -\r\n\r\ncat &lt;&lt;EOF &gt;\/etc\/apt\/sources.list.d\/kubernetes.list\r\ndeb http:\/\/apt.kubernetes.io\/ kubernetes-xenial main\r\nEOF\r\n\r\napt update\r\napt install -y kubelet kubeadm kubectl\r\n<\/pre>\n<h3>CentOS 7:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncat &lt;&lt;EOF &gt; \/etc\/yum.repos.d\/kubernetes.repo\r\n[kubernetes]\r\nname=Kubernetes\r\nbaseurl=https:\/\/packages.cloud.google.com\/yum\/repos\/kubernetes-el7-x86_64\r\nenabled=1\r\ngpgcheck=1\r\nrepo_gpgcheck=1\r\ngpgkey=https:\/\/packages.cloud.google.com\/yum\/doc\/yum-key.gpg https:\/\/packages.cloud.google.com\/yum\/doc\/rpm-package-key.gpg\r\nEOF\r\n\r\nsetenforce 0\r\n\r\nyum install -y kubelet kubeadm kubectl\r\n<\/pre>\n<p><!--more--><\/p>\n<p>Add to autorun and run:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsystemctl enable kubelet &amp;&amp; systemctl start kubelet\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>We initialize the <strong>Kubernetes<\/strong> cluster:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkubeadm init --apiserver-advertise-address=1.2.3.4 --pod-network-cidr=10.244.0.0\/16 --kubernetes-version stable-1.12\r\n<\/pre>\n<ul>\n<li><strong>&#8212;apiserver-advertise-address<\/strong> &#8212; sets the IP address to which Kubernetes will broadcast the API, the default is &quot;<strong>0.0.0.0<\/strong>&quot;<\/li>\n<li><strong>&#8212;pod-network-cidr<\/strong> -to use an alternative private network range, the default is &quot;<strong>10.96.0.0\/12<\/strong>&quot;<\/li>\n<li><strong>&#8212;kubernetes-version<\/strong> &#8212; rigidly sets a specific version for the cluster, the default is &quot;<strong>stable-1<\/strong>&quot;<\/li>\n<\/ul>\n<p>If everything is successful, then you will see something like the following:<\/p>\n<pre>Your Kubernetes master has initialized successfully!\r\n\r\nTo start using your cluster, you need to run the following as a regular user:\r\n\r\nmkdir -p $HOME\/.kube\r\nsudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\r\nsudo chown $(id -u):$(id -g) $HOME\/.kube\/config\r\n\r\nYou should now deploy a pod network to the cluster.\r\nRun \"kubectl apply -f [podnetwork].yaml\" with one of the options listed at:\r\nhttps:\/\/kubernetes.io\/docs\/concepts\/cluster-administration\/addons\/\r\n\r\nYou can now join any number of machines by running the following on each node\r\nas root:\r\n\r\nkubeadm join 1.2.3.4:6443 --token w70rla.kck3wg7lp85x8wlo --discovery-token-ca-cert-hash sha256:ea4a8a533dc61574e7794f7322ae2b29e531fd9f944d7e9f80e367ebd22e4470<\/pre>\n<p>As is clear from the conclusion, it is necessary from an ordinary user (if suddenly there is none, create) to do the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmkdir -p $HOME\/.kube\r\nsudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\r\nsudo chown $(id -u):$(id -g) $HOME\/.kube\/config\r\n<\/pre>\n<p>If there is no regular user in the system, you must create it with the <strong>sudo<\/strong> privilege:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nuseradd kubernetes -G sudo -m -s \/bin\/bash\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Kubectl<\/strong> has <strong>autocompletion<\/strong>, for this, the &quot;<strong>bash-completion<\/strong>&quot; package must be installed on the system. For the <strong>bash<\/strong> shell, do the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\necho &quot;source &lt;(kubectl completion bash)&quot; &gt;&gt; ~\/.bashrc\r\n<\/pre>\n<p>For <strong>MacOS<\/strong> or the <strong>zsh<\/strong> shell, see the Kubernetes <a href=\"https:\/\/kubernetes.io\/docs\/tasks\/tools\/install-kubectl\/#enabling-shell-autocompletion\" target=\"_blank\" rel=\"noopener noreferrer\">documentation<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>Install <strong>Flannel<\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkubectl apply -f https:\/\/raw.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/kube-flannel.yml\r\n<\/pre>\n<p>Restart <strong>Kubernetes<\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsystemctl restart kubelet\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Add another node to our cluster.<\/p>\n<p>On it, after repeating the installation steps of <strong>Docker<\/strong> and <strong>Kubernetes<\/strong>, we will start them and that\u2019s all, initialization is done only on the wizard when creating the cluster.<\/p>\n<p>From the root, we will execute the command received at the initialization stage of the cluster:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkubeadm join 1.2.3.4:6443 --token w70rla.kck3wg7lp85x8wlo --discovery-token-ca-cert-hash sha256:ea4a8a533dc61574e7794f7322ae2b29e531fd9f944d7e9f80e367ebd22e4470\r\n<\/pre>\n<p>Verify that cluster nodes are allowed access on <strong>TCP<\/strong> port <strong>6443<\/strong>.<\/p>\n<p>Now, back to the master, and from a regular user, we can see a list of nodes in the cluster:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkubectl get nodes\r\n<\/pre>\n<p>You can set the role of the node as follows:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkubectl label node NODE_NAME node-role.kubernetes.io\/worker=worker\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First you need to install Docker. For Kubernetes to work correctly, you must disable SWAP Also check delete it with fstab Add Kubernetes repository and install Ubuntu: CentOS 7:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[399,559],"tags":[549,551],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1698"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1698"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1698\/revisions"}],"predecessor-version":[{"id":1700,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1698\/revisions\/1700"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}