{"id":931,"date":"2020-02-19T16:29:18","date_gmt":"2020-02-19T14:29:18","guid":{"rendered":"https:\/\/www.rocworks.at\/wordpress\/?p=931"},"modified":"2020-02-19T16:29:18","modified_gmt":"2020-02-19T14:29:18","slug":"install-kubernetes-cluster","status":"publish","type":"post","link":"https:\/\/www.rocworks.at\/wordpress\/?p=931","title":{"rendered":"Install Kubernetes-Cluster"},"content":{"rendered":"<h2>Install Servers<\/h2>\n<p>I have used Ubuntu Server 18.04 LTS.<\/p>\n<p>Install one Master-Node and 3 Worker-Nodes.<\/p>\n<p>! Don&#8217;t clone the Ubuntu-VMs. I had troubles with networking when I have used cloned VMs. Even though the Mac-Addresses of the interfaces were different there were troubles with networking in Kubernetes.<\/p>\n<p>! Each node needs to have internet access! Because they will pull the docker images&#8230;.<\/p>\n<p>! You may setup your Master-Node also as Docker-Registry, so that the Nodes can pull images (self made images) from the Master.<\/p>\n<h2>Setup Network<\/h2>\n<p>We use 10.0.15.x as cluster network on a host-only vm network. In that case we set two IPs. The 192.168.163.x is the vm network, so that the VMs are accesible from your host (where the VMs are hosted on). The 10.0.15.x is the internal cluster network. Additionally we have a second interface with DHCP enabled, this interface should get a network in your public network with internet connection.<\/p>\n<p>vi \/etc\/netplan\/50-cloud-init.yaml<\/p>\n<pre><code>network:\n    ethernets:\n        ens33:\n            dhcp4: true\n            optional: true\n        ens38:\n            dhcp4: false\n            addresses: [10.0.15.10\/24, 192.168.163.10\/24]<\/code><\/pre>\n<pre><code>&gt; netplan apply<\/code><\/pre>\n<pre><code>&gt; vi \/etc\/hosts\n\n10.0.15.10  master\n10.0.15.21  worker01\n10.0.15.22  worker02\n10.0.15.23  worker02<\/code><\/pre>\n<pre><code>&gt; hostnamectl set-hostname master  \n&gt; reboot<\/code><\/pre>\n<h2>Install Docker<\/h2>\n<pre><code>&gt; apt install docker.io -y  <\/code><\/pre>\n<p>Systemd must be used for cgroupdriver in docker<\/p>\n<pre><code>&gt; cat &gt; \/etc\/docker\/daemon.json &lt;&lt;EOF\n{\n  \"exec-opts\": [\"native.cgroupdriver=systemd\"],\n  \"log-driver\": \"json-file\",\n  \"log-opts\": {\n    \"max-size\": \"100m\"\n  },\n  \"storage-driver\": \"overlay2\",\n  \"insecure-registries\" : [\"master:5000\"]   \n}\nEOF\n&gt; mkdir -p \/etc\/systemd\/system\/docker.service.d\n&gt; systemctl daemon-reload\n&gt; systemctl restart docker<\/code><\/pre>\n<h2>Install Docker Registry on Master<\/h2>\n<pre><code>&gt; docker run -d -p 5000:5000 --restart=always --name registry registry:2<\/code><\/pre>\n<p>add your Registry server as insecure registry to \/etc\/docker\/daemon.json, if you haven&#8217;t it done in one of the previous steps.<\/p>\n<pre><code>{   \n  \"insecure-registries\" : [\"master:5000\"]   \n}   <\/code><\/pre>\n<p>push an image to your Registry server:<\/p>\n<pre><code>&gt; docker tag &lt;image&gt; master:5000\/&lt;image&gt;   # tag your image\n&gt; docker push master:5000\/&lt;image&gt;  # push your image<\/code><\/pre>\n<h2>Install Kubernetes<\/h2>\n<p>Disable Swap<\/p>\n<pre><code>&gt; swapon -s  \n&gt; swapoff -a  \n&gt; vim \/etc\/fstab  # comment out line with swap device  \n&gt; reboot  <\/code><\/pre>\n<pre><code>&gt; apt install -y apt-transport-https  \n&gt; curl -s https:\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | apt-key add -  \n&gt; echo \"deb http:\/\/apt.kubernetes.io\/ kubernetes-xenial main\" &gt; \/etc\/apt\/sources.list.d\/&gt; kubernetes.list  \n&gt; apt update  \n&gt; apt install -y kubeadm kubelet kubectl  <\/code><\/pre>\n<h2>Master Node Cluster Initalization<\/h2>\n<pre><code>&gt; kubeadm config images pull\n&gt; kubeadm init --pod-network-cidr=10.244.10.0\/16 --apiserver-advertise-address=10.0.15.10  <\/code><\/pre>\n<p>Your Kubernetes control-plane has initialized successfully!<\/p>\n<p>To start using your cluster, you need to run the following as a regular user:<\/p>\n<pre><code>&gt; mkdir -p $HOME\/.kube\n&gt; sudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\n&gt; sudo chown $(id -u):$(id -g) $HOME\/.kube\/config<\/code><\/pre>\n<p>You should now deploy a pod network to the cluster (use a regular user)<\/p>\n<pre><code>&gt; kubectl apply -f https:\/\/raw.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/kube-flannel.yml<\/code><\/pre>\n<p>or<\/p>\n<pre><code>&gt; kubectl apply -f \"https:\/\/cloud.weave.works\/k8s\/net?k8s-version=$(kubectl version | base64 | tr -d 'n')\"<\/code><\/pre>\n<p>Check the state<\/p>\n<pre><code>&gt; kubectl get nodes  \n&gt; kubectl get pods --all-namespaces<\/code><\/pre>\n<h2>Join Worker Node(s)<\/h2>\n<p>Then you can join any number of worker nodes by running the following on each as root at the worker nodes (copy this from the outpout kubeadm init)<\/p>\n<pre><code>&gt; kubeadm join 10.0.15.10:6443 --token w8vr52.wtful961u754ev8b \n    --discovery-token-ca-cert-hash sha256:b07d512632b0117bfe81716b57d0c00b64cabd8222c5ffae04f447291a7c16f8<\/code><\/pre>\n<p>check if the nodes have been joined:<\/p>\n<pre><code>&gt; kubectl get nodes<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Install Servers I have used Ubuntu Server 18.04 LTS. Install one Master-Node and 3 Worker-Nodes. ! Don&#8217;t clone the Ubuntu-VMs. I had troubles with networking when I have used cloned VMs. Even though the Mac-Addresses of the interfaces were different there were troubles with networking in Kubernetes. ! Each node needs to have internet access! &hellip; <a href=\"https:\/\/www.rocworks.at\/wordpress\/?p=931\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Install Kubernetes-Cluster<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-931","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=931"}],"version-history":[{"count":1,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/931\/revisions"}],"predecessor-version":[{"id":932,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/931\/revisions\/932"}],"wp:attachment":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}