{"id":39950,"date":"2016-08-31T23:57:34","date_gmt":"2016-08-31T18:27:34","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=39950"},"modified":"2016-09-01T11:07:04","modified_gmt":"2016-09-01T05:37:04","slug":"understanding-kubernetes-architecture-and-setting-up-a-cluster-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/understanding-kubernetes-architecture-and-setting-up-a-cluster-on-ubuntu\/","title":{"rendered":"Understanding Kubernetes Architecture and Setting up a Cluster on Ubuntu"},"content":{"rendered":"<p>As we discussed previously &#8220;what is Kubernetes&#8221; and &#8220;what are the benefits of this orchestration tool&#8221;.\u00a0So, if you are wondering\u00a0what Kubernetes\u00a0is, for a better understanding, see <a href=\"http:\/\/www.tothenew.com\/blog\/getting-started-with-kubernetes\/\">getting started with kubernetes.<\/a> Now, in this blog we are here to discuss about running Kubernetes cluster\u00a0on bare-metal.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-40026\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/joining-forces.png\" alt=\"joining-forces\" width=\"430\" height=\"151\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/joining-forces.png 379w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/joining-forces-300x105.png 300w\" sizes=\"(max-width: 430px) 100vw, 430px\" \/><\/p>\n<p>In order to have better understanding of the architecture we decided to <a title=\"devops as a service\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">deploy Kubernetes<\/a> on bare-metal. Before setting up Kubernetes on bare-metal, we will discuss the architecture of Kubernetes. In the previous blog, we have discussed the basic term that what is master node,pods, kubectl, etc. and some generally used commands, so let&#8217;s have a deep dive on the architecture.<br \/>\n&nbsp;<\/p>\n<h1><span style=\"color: #ff9900;\">Kubernetes Architecture<\/span><\/h1>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-39958\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/kube7-arch.png\" alt=\"kube7-arch\" width=\"620\" height=\"363\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/kube7-arch.png 620w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/kube7-arch-300x175.png 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000080;\">Master Node Architecture<\/span><\/h2>\n<p><strong>Etcd<\/strong>: It is an open source key-value store developed by CoreOs team. Kubernetes uses &#8216;Etcd&#8217; to store the configuration data accessed by all nodes (minions and master) in the cluster.<\/p>\n<p><strong>Kube-ApiServer:<\/strong> \u00a0The Kubernetes api-server generally validates the configuration data store in &#8216;Etcd&#8217; and the details of the deployed container that are in agreement. It also provides a RESTful interface to make communication easy.<\/p>\n<p><strong>Kube-Schedule Server<\/strong>: It is responsible for assigning task to minions in the cluster.<\/p>\n<p><strong>Kube-Controller-Manager:<\/strong> It is generally responsible for handling the cluster level function such as replication controller. Whenever the desired state of the cluster changes it is written to Etcd and then the controller manager tries to bring up the cluster in the desired state.<\/p>\n<h2><span style=\"color: #000080;\">Minion Node Architecture<\/span><\/h2>\n<p><strong>Docker:<\/strong> One of \u00a0the basic requirement of nodes is Docker. Docker is responsible for pulling down and running container from Docker images. Read here for more information on <a href=\"http:\/\/www.tothenew.com\/blog\/what-is-docker-and-why-use-it\/\">docker<\/a>\u00a0.<\/p>\n<p><strong>Kube-Proxy:<\/strong> Every node in the cluster runs a simple network proxy. Using proxy node in cluster routes request to the correct container in a node.<\/p>\n<p><strong>Kubelet<\/strong>: It is an agent process that runs on each node. It is responsible for managing pods and their containers. It deal with pods specifications which are defined in YAML or JSON format. Kubelet takes the pod specifications and checks whether the pods are running healthy or not.<\/p>\n<p><strong>Flannel<\/strong>: It is an overlay network that works on assigning \u00a0a range of subnet address. It is used to assign IPs to each pods running in the cluster and to make the \u00a0pod-to-pod \u00a0and pod-to-services communications.<br \/>\n&nbsp;<\/p>\n<h1><span style=\"color: #ff9900;\">Setup Kubernetes on Ubuntu (Bare-metal)\u00a0<\/span><\/h1>\n<h3><span style=\"color: #000080;\"><b>Prerequisites for each server:<\/b><\/span><\/h3>\n<ul>\n<li>Linux Bridge utils Package [To install : sudo apt-get install bridge-utils ]<\/li>\n<li><span style=\"font-weight: 400;\">Docker<\/span><\/li>\n<li><strong><span style=\"font-weight: 400;\">ssh-agent configured\u00a0properly<\/span><\/strong><\/li>\n<li>All server have ssh-logged in using key authentication<\/li>\n<li>All nodes private-key identity must be added in master node for SSH communication.<\/li>\n<\/ul>\n<h3><span style=\"color: #000080;\">Steps:<\/span><\/h3>\n<ol>\n<li><span style=\"font-weight: 400;\">git clone &#8211;depth 1 <\/span><span style=\"font-weight: 400;\">https:\/\/github.com\/kubernetes\/kubernetes.git<\/span><\/li>\n<li><strong><strong><strong><span style=\"font-weight: 400;\">Configure the cluster information in kubernetes\/cluster\/ubuntu\/conf-default.sh file:<\/span><\/strong><\/strong><\/strong>\n<p>[js]export nodes=&quot;root@ip root@ip root@ip&quot;<br \/>\nexport role=&quot;a i i&quot;<br \/>\nexport NUM_NODES=${NUM_NODES:-2}<br \/>\nexport SERVICE_CLUSTER_IP_RANGE=192.168.3.0\/24<br \/>\nexport FLANNEL_NET=172.16.0.0\/16[\/js]<\/p>\n<p>Change these variables ,the variable &#8220;node&#8221; defines all the cluster nodes, &#8220;roles&#8221; defines what role should assign to each node and &#8220;num_nodes&#8221; define the number of minions.<br \/>\n<b><i>Note:<\/i><\/b><br \/>\n<i><span style=\"font-weight: 400;\">Role \u201ca\u201d for master and \u201ci\u201d for node (minion)<\/span><\/i><strong><strong><i><br \/>\n<span style=\"font-weight: 400;\">Flannel_net ip should not be the same as cluster CIDR address.<\/span><\/i><\/strong><\/strong><\/li>\n<li>After all the variables are configured\u00a0correctly, run config-default.sh:\n<p>[js] cd\u00a0kubernetes\/cluster\/ubuntu<br \/>\n\u00a0.\/config-default.sh[\/js]<\/p>\n<p>Now, all variables are now set for\u00a0that particular session.<\/li>\n<li>The following command will bring online the whole cluster:\n<p>[js]cd\u00a0kubernetes\/cluster\/<br \/>\nKUBERNETES_PROVIDER=ubuntu .\/kube-up.sh[\/js]<\/p>\n<p>The script automatically copies all config and binaries files using scp and starts Kubernetes services on each node.<\/li>\n<li>Now, that the cluster has been setup, we can check by running kubectl on master node. Firstly, export all binaries into bashrc:\n<p>[js]export PATH=$PATH:\/homedirectory\/kubernetes\/cluster\/ubuntu\/binaries<br \/>\nsource .bashrc<br \/>\nkubectl get nodes[\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-40000 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/nodes2.png\" alt=\"nodes\" width=\"352\" height=\"67\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/nodes2.png 352w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/nodes2-300x57.png 300w\" sizes=\"(max-width: 352px) 100vw, 352px\" \/><\/li>\n<li>Now, Deploy Addons like DNS and UI to manage Kubernetes through UI:\n<p>[js]cd\u00a0kubernetes\/cluster\/ubuntu<br \/>\nKUBERNETES_PROVIDER=ubuntu .\/deployAddons.sh[\/js]<\/p>\n<\/li>\n<li><strong>Access UI:<\/strong> <em><em>http:\/\/master_node_ip:8080\/UI<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-39992\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/ui.png\" alt=\"ui\" width=\"1361\" height=\"577\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/ui.png 1361w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/ui-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/ui-1024x434.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/ui-624x264.png 624w\" sizes=\"(max-width: 1361px) 100vw, 1361px\" \/><br \/>\n<\/em><\/em><\/li>\n<\/ol>\n<p>I hope this will help in understanding the architecture and how to\u00a0setup Kubernetes on Ubuntu. In my next blog, we will setup auto-scaling in pods using external load-balancer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we discussed previously &#8220;what is Kubernetes&#8221; and &#8220;what are the benefits of this orchestration tool&#8221;.\u00a0So, if you are wondering\u00a0what Kubernetes\u00a0is, for a better understanding, see getting started with kubernetes. Now, in this blog we are here to discuss about running Kubernetes cluster\u00a0on bare-metal. In order to have better understanding of the architecture we decided [&hellip;]<\/p>\n","protected":false},"author":917,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"link","meta":{"iawp_total_views":11},"categories":[2348,1],"tags":[248,2366,1892,1883,3965,3977,3979,3978,3970],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/39950"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/917"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=39950"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/39950\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=39950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=39950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=39950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}