<?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>traefik &#8211; richliu&#039;s blog</title>
	<atom:link href="https://richliu.com/tag/traefik/feed/" rel="self" type="application/rss+xml" />
	<link>https://richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Thu, 21 Nov 2019 14:04:13 +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 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 fetchpriority="high" 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 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="(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 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="(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>
