<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>metallb &#8211; richliu&#039;s blog</title>
	<atom:link href="https://richliu.com/tag/metallb/feed/" rel="self" type="application/rss+xml" />
	<link>https://richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Sat, 16 Sep 2023 16:46:48 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>ARM64 Kubernetes Qemu Metallb Linkerd Numa</title>
		<link>https://richliu.com/2023/09/17/5329/arm64-kubernetes-qemu-metallb-linkerd-numa/</link>
					<comments>https://richliu.com/2023/09/17/5329/arm64-kubernetes-qemu-metallb-linkerd-numa/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sat, 16 Sep 2023 16:46:48 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[kubernetes]]></category>
		<category><![CDATA[libvirt]]></category>
		<category><![CDATA[linkerd]]></category>
		<category><![CDATA[metallb]]></category>
		<category><![CDATA[numa]]></category>
		<category><![CDATA[qemu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5329</guid>

					<description><![CDATA[<p>Sometime I feelt hat k8s make me frustrated, Latest tim [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/09/17/5329/arm64-kubernetes-qemu-metallb-linkerd-numa/">ARM64 Kubernetes Qemu Metallb Linkerd Numa</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Sometime I feelt hat k8s make me frustrated,  Latest time I wrote this document is 4 years ago, that&#8217;s old version, but when I want to use k8s as container manager again, seems that something different and network won&#8217;t work, original document cannot work anymore, it needs to have new document to record that. </p>



<p>My hardware also different, if you don&#8217;t have such powerful machine, it can skip numa part, that&#8217;s only for high end ARM64 machine. <br />The hardware is <a href="https://amperecomputing.com/systems/altra/2u-mt-collins-2s-sas-3.5" target="_blank" rel="noreferrer noopener">Ampere Mt. Collins</a> which has 2*Ampere Altra 80 Cores CPU and 8*32G Memory, my experiment is run different VM on different CPU, to seperate them and lock it on different numa node. </p>



<span id="more-5329"></span>



<p>There are two CPUs, so, it can create 3 nodes, so, I have plan to allocate resource like that. <br />1. k8s master on socket 0: 10 CPUs, 16G memory <br />2. k8s node1 on socket 0 : 70 CPUs, 100G memory <br />3. k8s node2 on socket 1:  80 CPUs, 120G memory </p>



<p>Kubernetes version v1.28.2<br />Ubuntu 22.04</p>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Notice: Before reading this document, this document is personal experiment, not Ampere official document, take your own risk. </mark></strong></p>



<h2 class="wp-block-heading">Prepare VM from libvirt </h2>



<p>The server has remote control system which problem sufficent resolution to use GUI on server, so, I install ubuntu 22.04 on host system, than use virt-manager to create k8s master node, for qemu image, I create the disk image alone, seems create image when run install will allocate all disk space, seems that&#8217;s a virt-manager bug. <br />And the host network is configured to be a bridge interface, in my case, that&#8217;s br0. </p>



<p>So, when uses virt-manager to create VM, it can bridge network interface to br0. </p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="2125" height="1179" src="https://richliu.com/wp-content/uploads/2023/09/image-1.png" alt="" class="wp-image-5330" srcset="https://richliu.com/wp-content/uploads/2023/09/image-1.png 2125w, https://richliu.com/wp-content/uploads/2023/09/image-1-600x333.png 600w, https://richliu.com/wp-content/uploads/2023/09/image-1-768x426.png 768w, https://richliu.com/wp-content/uploads/2023/09/image-1-1536x852.png 1536w, https://richliu.com/wp-content/uploads/2023/09/image-1-2048x1136.png 2048w" sizes="(max-width: 2125px) 100vw, 2125px" /><figcaption class="wp-element-caption">After installed first VM, it can copy the master image to another VMs images and named it as k8s-node1 and k8s-node2. <br />need to modify the /etc/hostname, /etc/hosts and /etc/netplan/00-installer-config.yaml in the guest. <br />Remeber to change the CPU number and memory size on virt-manager GUI, different VM needs to use different VM image. it can keep other options by default. </figcaption></figure>



<h2 class="wp-block-heading">Configure the VM with Numa </h2>



<p>It can use numastat to check currnet numa status, this system has two numa nodes. it can use numastat and numactl to get more numa information.</p>



<pre class="wp-block-preformatted"># numastat -n

Per-node numastat info (in MBs):
                          Node 0          Node 1           Total
                 --------------- --------------- ---------------
Numa_Hit               591239.17       791075.41      1382314.58
Numa_Miss                   0.00            0.00            0.00
Numa_Foreign                0.00            0.00            0.00
Interleave_Hit              8.63            7.13           15.77
Local_Node             519434.17       777974.99      1297409.16
Other_Node              71805.00        13100.42        84905.42

# numactl --hardware
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
node 0 size: 128377 MB
node 0 free: 80224 MB
node 1 cpus: 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
node 1 size: 126426 MB
node 1 free: 93888 MB
node distances:
node   0   1
  0:  10  20
  1:  20  10</pre>



<p>virt-manager doesn&#8217;t have advance command to assign CPU, probably modify xml can get that purpose, but it more converince to use the &#8220;virsh&#8221; cli command to adjust VM parameters. &#8220;virsh list&#8221; show current VMs, &#8220;virsh vcpupin list current VM CPU scheduling&#8221;, &#8220;virsh vcpupin <em>domain-id vcpu cpulist</em>&#8221; to modify the VCPU run on which one CPU. </p>



<p>For memory, it needs to use &#8220;virsh numatune&#8221; to lock the memory on different node. <br />&#8220;virsh numatune domain [&#8211;mode mode] [&#8211;nodeset nodeset] [[&#8211;config] [&#8211;live] | [&#8211;current]]&#8221;, &#8211;current can update current running VM machine. </p>



<pre class="wp-block-preformatted">$ virsh list
 Id   Name          State
-----------------------------
 9    k8s-master   running
 10   k8s-node1     running

$ virsh vcpupin k8s-master
 VCPU   CPU Affinity
----------------------
 0      0-159
 1      0-159
 2      0-159
 3      0-159
 4      0-159
 5      0-159
 6      0-159
 7      0-159
 8      0-159
 9      0-159

# this command can lock 9 k8s-master's VCPU 0 on physical CPU 0. 
$ virsh vcpupin 9 0 0 

# Show current VM's numatune, for example, following is unset status. 
$ virsh numatune 9
numa_mode      : strict
numa_nodeset   :

$ virsh numatune 9 --nodeset 0

# the numa_nodeset was set to 0
$ virsh numatune 9
numa_mode      : strict
numa_nodeset   : 0

</pre>



<p>The problem is, seems this script need to run everytime, alternativate solution is to modify XML, but Mt. collis has 160 cores, I won&#8217;t to modify the XML file. script is more converience on this situation, following is my sample script to adjust k8s-master, k8s-node1, and k8s-node2&#8217;s parameter, it can easy to modify it if you install other system or AltraMax CPU. </p>



<pre class="wp-block-preformatted">#!/bin/bash

configure_vm(){
        local VM_NAME="$1"
        local VM_VCPU="$2"
        local VM_CPU="$3"
        local VM_NUMA="$4"
        local VM_TYPE="$5" # VM_TYPE for MASTER or NODE0, NODE1 .. self define name

        id=$(virsh list | grep $VM_NAME | awk '{print $1}')
        state=$(virsh list | grep $VM_NAME | awk '{print $3}')

        if [ "$state" != "running" ]; then
          echo "$VM_TYPE is not running"
          exit 1
        else
          echo "configure $VM_TYPE"
        fi
        numa_nodeset=$(virsh numatune $id | grep numa_nodeset | awk '{print $3}')

        start_cpu=$(echo $VM_VCPU | cut -d'-' -f1)
        end_cpu=$(echo $VM_VCPU | cut -d'-' -f2)
        for ((vcpu = start_cpu; vcpu &lt;= end_cpu; vcpu++)); do
          # echo "$id $vcpu $VM_CPU"
          virsh vcpupin $id $vcpu $VM_CPU > /dev/null
        done
        if [ -n "$numa_nodeset" ]; then
          echo "$VM_TYPE numa_nodeset is $numa_nodeset"
        else
          # echo "$id $VM_NUMA"
          virsh numatune $id --nodeset $VM_NUMA
        fi
}

configure_vm "k8s-master" "0-9" "0-9" "0" "Master"
configure_vm "k8s-node1" "0-69" "10-79" "0" "Node0"
configure_vm "k8s-node2" "0-79" "80-159" "1" "Node1"


====

# After run the script, it can run numastat &lt;pid> to see the qemu runs numa status. ex:
$ sudo numastat 206601

Per-node process memory usage (in MBs) for PID 206601 (qemu-system-aar)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                        11.51            0.00           11.51
Stack                        0.04            0.00            0.04
Private                   5984.93            0.00         5984.94
----------------  --------------- --------------- ---------------
Total                     5996.48            0.00         5996.48

</pre>



<p>In here, on socket 0 , 0-9 and 0-69 is vcpu, so, all start from 0. After run this script, it can use &#8220;virsh vcpupin&#8221; and &#8220;virsh numatune&#8221; to get current setting. Maybe cpuset parameter in XML can more easy to get this function, but I have not try it. </p>



<p></p>



<h2 class="wp-block-heading">Install K8s </h2>



<p>Here is my script, just reference some later blog and my previous configurtion script, so, it can copy and paste to system and run it directly. </p>



<p>Install basic system and k8s</p>



<pre class="wp-block-preformatted"># setup timezone
sudo apt install ntpdate -y
sudo ntpdate watch.stdtime.gov.tw
sudo timedatectl set-timezone Asia/Taipei

# install and enable docker

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt update
sudo apt install -y containerd.io

containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&amp;1
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

sudo systemctl restart containerd
sudo systemctl enable containerd

echo "----------------"
echo "   swapoff"
echo "----------------"
sudo swapoff -a
sudo sed -i '/swap/ s/^\(.*\)$/#\1/g' /etc/fstab

# Install k8s
sudo apt -y install apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update

sudo apt-get -y install kubelet
sudo apt-get -y install kubeadm
sudo apt-get -y install kubectl
sudo apt-mark hold kubelet kubeadm kubectl

# Update kernel parametes
cat &lt;&lt;EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

# update sysctl
sudo sysctl --system

sudo tee /etc/modules-load.d/containerd.conf &lt;&lt;EOF
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter

echo "if this is work node, it can run kubeadm join now"

echo "alias k=kubectl" >> .bashrc</pre>



<h3 class="wp-block-heading">Setup Master Node</h3>



<p>Run this script on master node. </p>



<pre class="wp-block-preformatted">sudo kubeadm init --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

# echo "enable master to run pods"
# kubectl taint nodes --all node-role.kubernetes.io/master-
</pre>



<p>It will shows some message below, then run it on k8s-node1 and k8s-node2</p>



<p>kubeadm join 192.168.110.230:6443 &#8211;token e14f7k.35c3jpny81ry70re \</p>



<p>        &#8211;discovery-token-ca-cert-hash sha256:6636a7e4ec3542f19152f308f0789c52287b743b60efa3c13e7c23ce1147c581</p>



<p>If forgot command above, it can create another token to let other k8s node join, ex:</p>



<pre class="wp-block-preformatted">kubeadm token create --print-join-command</pre>



<h3 class="wp-block-heading">Flannel : Network fabric for container</h3>



<p>K8s need a network fabric to provide internal network topology, there are many choices, but we will install matellb later, some other network like calico might have potential issue, so, we choice flannel as network fabric.</p>



<pre class="wp-block-preformatted">kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml</pre>



<p>After run this command, the k8s node status will change to Ready, if not install network fabric, the node status will be NotReady. </p>



<pre class="wp-block-preformatted">$ kubectl get nodes
NAME         STATUS   ROLES           AGE   VERSION
k8s-master   Ready    control-plane   26h   v1.28.2
k8s-node1    Ready    &lt;none>          26h   v1.28.2
k8s-node2    Ready    &lt;none>          26h   v1.28.2</pre>



<h3 class="wp-block-heading">Helm: Kubbernetes Applications Manager</h3>



<p>Install helm to further install metallb purpose, on previous article, helm2 needs another application to connect to k8s, but helm3 doesn&#8217;t need it, more easy to use on k8s. </p>



<pre class="wp-block-preformatted">curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 -o /tmp/get_helm.sh
chmod 700 /tmp/get_helm.sh
sudo /tmp/get_helm.sh</pre>



<h3 class="wp-block-heading">Metallb: Bere metal load-balancer for K8s</h3>



<p>Install k8s on private side, it needs load-balancer to provide external IP to communication with internet or intranet. If you install Metallb, the &#8220;kubectl get svc&#8221;, the EXTERNAL-IP shows &#8220;Pending&#8221;, and k8s doesn&#8217;t response the arp on host, probably it doesn&#8217;t configure kube-proxy, it you have experience on previous metallb installtion, it might miss this part. </p>



<pre class="wp-block-preformatted">PATH=$PATH:/usr/local/bin/

helm repo add metallb https://metallb.github.io/metallb
helm --namespace metallb-system install --create-namespace metallb metallb/metallb -f metallb-values.yaml

# https://metallb.universe.tf/installation/
# see what changes would be made, returns nonzero returncode if different
kubectl get configmap kube-proxy -n kube-system -o yaml | \
        sed -e "s/strictARP: false/strictARP: true/" | \
        kubectl diff -f - -n kube-system

# actually apply the changes, returns nonzero returncode on errors only
kubectl get configmap kube-proxy -n kube-system -o yaml | \
        sed -e "s/strictARP: false/strictARP: true/" | \
        kubectl apply -f - -n kube-system
</pre>



<p>metallb-values.yaml is also different like previous setting, it needs to configure L2Advertisement on metallb, without it, your metallb won&#8217;t work. Follwing is metallb-values.yaml  file. </p>



<pre class="wp-block-preformatted">apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: primary-pool
  namespace: metallb-system
spec:
  addresses:
  - 192.168.110.200-192.168.110.219

---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: l2adv
  namespace: metallb-system
spec:
  ipAddressPools:
  - primary-pool
</pre>



<h3 class="wp-block-heading">Traefik: TBD</h3>



<h3 class="wp-block-heading">Linkerd</h3>



<p>Just show the install script here</p>



<pre class="wp-block-preformatted">curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh

echo "export PATH=$PATH:/home/$USER/.linkerd2/bin" >> ~/.bashrc

linkerd install --crds | kubectl apply -f -
linkerd install | kubectl apply -f -
linkerd viz install | kubectl apply -f -</pre>



<h3 class="wp-block-heading">Other</h3>



<p>it can insert isolinux to host linux kernel parameter to isolate the Linux scheduling to k8s nodes. (TBD)</p>



<pre class="wp-block-preformatted">isolcpus=10-159 nohz=on nohz_full=10-159</pre>



<h2 class="wp-block-heading">Test with Nginx </h2>



<p>It can deploy nginx to test this system </p>



<pre class="wp-block-preformatted">kubectl create deploy nginx --image=nginx
kubectl expose deploy nginx --port=80 --target-port=80 --type=LoadBalancer
kubectl get svc nginx
NAME    TYPE           CLUSTER-IP      EXTERNAL-IP       PORT(S)        AGE
nginx   LoadBalancer   10.99.211.255   192.168.110.200   80:31011/TCP   25h</pre>



<p>Now, it can try to access http://192.168.110.200. <br />if want to Delete nginx deploy, run following command. </p>



<pre class="wp-block-preformatted">kubectl delete deploy nginx
kubectl delete svc nginx</pre>



<h2 class="wp-block-heading">Test Numa</h2>



<p>It can run emojivoto to test the system only runs on socket1, use it because it can general a lot of traffic between pods. </p>



<pre class="wp-block-preformatted">curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/emojivoto.yml \
  | kubectl apply -f -</pre>



<p>Now it can use htop to show all CPUs, and we can see most traffic on CPU 1~10 and 81~160. There are a little CPU usage on CPU 78 and 80, but it should be Linux regular scheduling(I have not add isocpu to host CPU this time)</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1982" height="857" src="https://richliu.com/wp-content/uploads/2023/09/image-2.png" alt="" class="wp-image-5338" srcset="https://richliu.com/wp-content/uploads/2023/09/image-2.png 1982w, https://richliu.com/wp-content/uploads/2023/09/image-2-600x259.png 600w, https://richliu.com/wp-content/uploads/2023/09/image-2-768x332.png 768w, https://richliu.com/wp-content/uploads/2023/09/image-2-1536x664.png 1536w" sizes="(max-width: 1982px) 100vw, 1982px" /><figcaption class="wp-element-caption">ref.<br /><a href="https://richliu.com/2019/11/01/4197/arm64-kubernetes-nginx-traefik-ingress-load-balance/" target="_blank" rel="noreferrer noopener">ARM64 Kubernetes Nginx Traefik Ingress Load Balance</a><br /><a href="https://richliu.com/2019/09/25/4160/install-kubernetes-on-arm64-ubuntu-18-04/" target="_blank" rel="noreferrer noopener">Install Kubernetes on ARM64 Ubuntu 18.04 (with QEMU)</a><br /><a href="https://richliu.com/2020/01/14/4256/kubernetes-install-nginx-ingress-on-arm64/" target="_blank" rel="noreferrer noopener">Kubernetes install nginx-ingress on ARM64</a><br /><a href="https://metallb.universe.tf/troubleshooting/" target="_blank" rel="noreferrer noopener">TROUBLESHOOTING METALLB</a><br /><a href="https://github.com/metallb/metallb/issues/1591" target="_blank" rel="noreferrer noopener">Reassignment Duplicate IP after deleting IP pool #1591</a><br /><a href="https://access.redhat.com/documentation/zh-tw/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/sect-virtualization_tuning_optimization_guide-numa-numa_and_libvirt" target="_blank" rel="noreferrer noopener">9.3. libvirt NUMA Tuning</a><br /></figcaption></figure>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/09/17/5329/arm64-kubernetes-qemu-metallb-linkerd-numa/">ARM64 Kubernetes Qemu Metallb Linkerd Numa</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2023/09/17/5329/arm64-kubernetes-qemu-metallb-linkerd-numa/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ARM64 Kubernetes Nginx Traefik Ingress Load Balance</title>
		<link>https://richliu.com/2019/11/01/4197/arm64-kubernetes-nginx-traefik-ingress-load-balance/</link>
					<comments>https://richliu.com/2019/11/01/4197/arm64-kubernetes-nginx-traefik-ingress-load-balance/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Fri, 01 Nov 2019 11:47:07 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[kubernetes]]></category>
		<category><![CDATA[metallb]]></category>
		<category><![CDATA[traefik]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4197</guid>

					<description><![CDATA[<p>My original target purpose is very simple, build deploy [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/11/01/4197/arm64-kubernetes-nginx-traefik-ingress-load-balance/">ARM64 Kubernetes Nginx Traefik Ingress Load Balance</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>My original target purpose is very simple, build deploy several webserver and assigned a external ip for internet to access it. <br /><br />Most kubernetes newbie install guide won&#8217;t mention how to do that. actually that&#8217;s very simple, for external ip, it needs a load balance controller like metallb for create a external ip address to access web server. and an Ingress contoller like Traefik for http/https route to right pods .</p>



<span id="more-4197"></span>



<figure class="wp-block-image"><img decoding="async" src="https://i1.wp.com/www.devtech101.com/wp-content/uploads/2019/02/metal-lb_part1.png?resize=648%2C314&amp;ssl=1" alt=""/><figcaption>ref:  <a href="https://www.devtech101.com/2019/02/23/using-metallb-and-traefik-load-balancing-for-your-bare-metal-kubernetes-cluster-part-1/" target="_blank" rel="noopener">Using MetalLB And Traefik for Load balancing on your Bare Metal Kubernetes Cluster – Part 1</a> </figcaption></figure>



<p>Above is a figure to describe relationship about metallb/traefik and kubernetes. <br /><br />Please reference previous article (<a href="https://richliu.com/2019/09/25/4160/install-kubernetes-on-arm64-ubuntu-18-04">Install Kubernetes on ARM64 Ubuntu 18.04</a>)about how to setup environment. </p>



<h3 class="wp-block-heading">Install Helm</h3>



<p>First, install Helm, helm is a kubernetes packages manager. it can help to install traefik, for some package, like traefik, it&#8217;s not easy to install manually, I tried, but fail. Use helm to install is a good idea. <br /><br />Following instruction can download and install helm, or you can visit helm webpage for latest version <br /><br />Following is command to download and install helm.</p>



<pre class="wp-block-preformatted">wget https://get.helm.sh/helm-v2.15.1-linux-arm64.tar.gz
tar xvf helm-v2.15.1-linux-arm64.tar.gz
sudo mv linux-arm64/helm /usr/bin</pre>



<p>Default helm(tiller seems doesn&#8217;t support ARM64 archeticture, so, it needs to use third party binary code for tiller. In here we used <a href="https://github.com/jessestuart/tiller-multiarch" target="_blank" rel="noopener">tiller-multiarch</a>.  </p>



<pre class="wp-block-preformatted">helm init --tiller-image=jessestuart/tiller </pre>



<h4 class="wp-block-heading">Helm install error message </h4>



<p>When you run helm install command, if see error message like below, please try to follow this step to solve it. (ref: <a rel="noreferrer noopener" aria-label="TILLER AND ROLE-BASED ACCESS CONTROL (opens in a new tab)" href="https://helm.sh/docs/using_helm/#tiller-and-role-based-access-control" target="_blank">TILLER AND ROLE-BASED ACCESS CONTROL</a> and <a rel="noreferrer noopener" aria-label="forbidden: User &quot;system:serviceaccount:kube-system:default&quot; cannot get namespaces in the namespace &quot;default (opens in a new tab)" href="https://github.com/fnproject/fn-helm/issues/21" target="_blank">forbidden: User &#8220;system:serviceaccount:kube-system:default&#8221; cannot get namespaces in the namespace &#8220;default</a>)<br /><br />Create a rbac-config.yaml like following text<br />(ref. <a href="https://github.com/helm/helm/issues/3130" target="_blank" rel="noopener">User &#8220;system:serviceaccount:kube-system:default&#8221; cannot get namespaces in the namespace &#8220;default&#8221;</a> )</p>



<pre class="wp-block-code"><code>apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: default</code></pre>



<p>Run following command to create  and upgrade helm initial </p>



<pre class="wp-block-preformatted">kubectl create -f rbac-config.yaml
helm init --service-account tiller --history-max 200 --tiller-image=jessestuart/tiller --upgrade</pre>



<p>or run those commands directly. </p>



<pre class="wp-block-preformatted">kubectl create serviceaccount --namespace kube-system tiller<br />kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller<br />kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'<br />helm init --upgrade --service-account tiller </pre>



<h3 class="wp-block-heading">Install metallb </h3>



<h4 class="wp-block-heading">Automatically Install</h4>



<p>It can use helm to install automatically, first create a metallb-config.yaml, contain like below.</p>



<pre class="wp-block-preformatted">configInline:
   address-pools:
   - name: default 
     protocol: layer2
     addresses:
         - 192.168.110.80-192.168.110.100 </pre>



<p>Save it, and run follow command to apply it. </p>



<pre class="wp-block-preformatted">helm install --name=metallb --namespace=metallb-system -f  metallb-config.yaml stable/metallb </pre>



<figure class="wp-block-image"><img decoding="async" width="1024" height="641" src="https://richliu.com/wp-content/uploads/2019/10/image-1-1024x641.png" alt="" class="wp-image-4201" srcset="https://richliu.com/wp-content/uploads/2019/10/image-1-1024x641.png 1024w, https://richliu.com/wp-content/uploads/2019/10/image-1-300x188.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-1-768x481.png 768w, https://richliu.com/wp-content/uploads/2019/10/image-1.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h4 class="wp-block-heading">Manually Install</h4>



<p>It also can install metallb manually, run following command to install it.<br />It will install v0.8.1, it can visit <a rel="noreferrer noopener" aria-label="metallb website (opens in a new tab)" href="https://metallb.universe.tf/installation/" target="_blank">metallb website</a> to check latest version.</p>



<pre class="wp-block-preformatted">kubectl apply -f <a href="https://raw.githubusercontent.com/google/metallb/v0.8.1/manifests/metallb.yaml" target="_blank" rel="noopener">https://raw.githubusercontent.com/google/metallb/v0.8.1/manifests/metallb.yaml</a> </pre>



<p>Add a new file name metallb.yaml and put follow text</p>



<pre class="wp-block-preformatted">apiVersion: v1
kind: ConfigMap
metadata:
   namespace: metallb-system
   name: config
data:
   config: |
     address-pools:
     - name: my-ip-space
       protocol: layer2
       addresses:
       - 192.168.110.70/28</pre>



<p>Apply it</p>



<pre class="wp-block-preformatted">kubectl apply -f  metallb.yaml </pre>



<h3 class="wp-block-heading">Install Traefik</h3>



<p>Traefik is an open-source Edge Router that makes publishing your services a fun and easy experience.<br /><br />Following is command to initial helm and used helm to initial traefik. </p>



<pre class="wp-block-preformatted">helm install stable/traefik --name traefik --set dashboard.enabled=true,serviceType=NodePort,dashboard.domain=dashboard-traefik.techarea.org,rbac.enabled=true  --namespace kube-system</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="890" src="https://richliu.com/wp-content/uploads/2019/10/image-2-1024x890.png" alt="" class="wp-image-4202" srcset="https://richliu.com/wp-content/uploads/2019/10/image-2-1024x890.png 1024w, https://richliu.com/wp-content/uploads/2019/10/image-2-300x261.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-2-768x668.png 768w, https://richliu.com/wp-content/uploads/2019/10/image-2.png 1272w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h4 class="wp-block-heading">Traefik Dashboard</h4>



<p>When used helm to install traefik, it also install traefik dashboard on dashboard-traefik.techarea.org. <br /><br />Used following command to get traefik web service ip</p>



<pre class="wp-block-preformatted">kubectl describe svc traefik --namespace kube-system</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="589" src="https://richliu.com/wp-content/uploads/2019/10/image-6-1024x589.png" alt="" class="wp-image-4207" srcset="https://richliu.com/wp-content/uploads/2019/10/image-6-1024x589.png 1024w, https://richliu.com/wp-content/uploads/2019/10/image-6-300x173.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-6-768x442.png 768w, https://richliu.com/wp-content/uploads/2019/10/image-6.png 1081w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>It can see a http hosted on 10.44.0.2 , add 10.44.0.2 daskboard-traefik.techarea.org to browser PC&#8217;s hosts file, it can use browser to access traefik dashboard . </p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="550" src="https://richliu.com/wp-content/uploads/2019/10/image-7-1024x550.png" alt="" class="wp-image-4208" srcset="https://richliu.com/wp-content/uploads/2019/10/image-7-1024x550.png 1024w, https://richliu.com/wp-content/uploads/2019/10/image-7-300x161.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-7-768x413.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h3 class="wp-block-heading">Create a nginx web site </h3>



<p>In here, we create three nginx website, and assigned a external ip address, it will also assign a domain name, traefik will have load balance traffic to all three pods. <br /><br />First create a new file called nginx.yaml </p>



<pre class="wp-block-code"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 4
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1
        ports:
        - name: http
          containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/rule-type: "PathPrefixStrip"
  name: nginx
spec:
  rules:
  - host: nginx.techarea.org
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx
          servicePort: 80
</code></pre>



<p>replicas means how many pods you went to create, in here, we used 3, it will create 3 pods on clients. <br />host means url, in here is nginx.techarea.org. <br /><br />used kubectl to apply it. </p>



<pre class="wp-block-preformatted">kubectl apply -f nginx.yaml </pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="948" height="114" src="https://richliu.com/wp-content/uploads/2019/10/image-3.png" alt="" class="wp-image-4203" srcset="https://richliu.com/wp-content/uploads/2019/10/image-3.png 948w, https://richliu.com/wp-content/uploads/2019/10/image-3-300x36.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-3-768x92.png 768w" sizes="auto, (max-width: 948px) 100vw, 948px" /></figure>



<p>Get current service status </p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="101" src="https://richliu.com/wp-content/uploads/2019/10/image-4-1024x101.png" alt="" class="wp-image-4204" srcset="https://richliu.com/wp-content/uploads/2019/10/image-4-1024x101.png 1024w, https://richliu.com/wp-content/uploads/2019/10/image-4-300x30.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-4-768x76.png 768w, https://richliu.com/wp-content/uploads/2019/10/image-4.png 1187w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>We can see external ip is 192.168.110.80, add 192.168.110.80 nginx.techarea.org to your browser PC&#8217;s host file, and used browser to access nginx.techarea.org, it can see welcome nginx.  </p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="562" src="https://richliu.com/wp-content/uploads/2019/10/image-5-1024x562.png" alt="" class="wp-image-4206" srcset="https://richliu.com/wp-content/uploads/2019/10/image-5-1024x562.png 1024w, https://richliu.com/wp-content/uploads/2019/10/image-5-300x165.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-5-768x421.png 768w, https://richliu.com/wp-content/uploads/2019/10/image-5.png 1866w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">Test Load Balance</h3>



<p>Now we finished install traefik and metallb successfully, next step is to verified does that really work ?<br /><br />it can use another host to run ab (apache benchmark to do this test) and used htop observe CPU loading.  <br /><br />Following is example to test nginx, if don&#8217;t see all CPU has loading, try to increase pods instance, like 4 . </p>



<pre class="wp-block-preformatted">ab -n 1000000 -c 400 -k http://nginx.techarea.org/</pre>



<pre class="wp-block-preformatted">Below is example result for nginx load balance. </pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="394" src="https://richliu.com/wp-content/uploads/2019/10/image-9-1024x394.png" alt="" class="wp-image-4210" srcset="https://richliu.com/wp-content/uploads/2019/10/image-9-1024x394.png 1024w, https://richliu.com/wp-content/uploads/2019/10/image-9-300x115.png 300w, https://richliu.com/wp-content/uploads/2019/10/image-9-768x295.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>See, that&#8217;s easy job, right ? </p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/11/01/4197/arm64-kubernetes-nginx-traefik-ingress-load-balance/">ARM64 Kubernetes Nginx Traefik Ingress Load Balance</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/11/01/4197/arm64-kubernetes-nginx-traefik-ingress-load-balance/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
