<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bugra Ozturk on Medium]]></title>
        <description><![CDATA[Stories by Bugra Ozturk on Medium]]></description>
        <link>https://medium.com/@bugraoz93?source=rss-3eaa5ec9f16b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*caaNEjI97-3Qo8vE3g2ykA.jpeg</url>
            <title>Stories by Bugra Ozturk on Medium</title>
            <link>https://medium.com/@bugraoz93?source=rss-3eaa5ec9f16b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:55:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bugraoz93/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Active-Passive  Highly Availability: Janus Gateway on Kubernetes]]></title>
            <link>https://bugraoz93.medium.com/active-passive-highly-availability-janus-gateway-on-kubernetes-2189256e5525?source=rss-3eaa5ec9f16b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2189256e5525</guid>
            <category><![CDATA[application-load-balancer]]></category>
            <category><![CDATA[janus-gateway]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[Bugra Ozturk]]></dc:creator>
            <pubDate>Wed, 24 Mar 2021 18:55:11 GMT</pubDate>
            <atom:updated>2021-05-03T12:48:27.950Z</atom:updated>
            <content:encoded><![CDATA[<h3>Active-Passive Highly Availability: Janus Gateway on Kubernetes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*ya1pDDWOiJWbMeXlzwkt2Q.jpeg" /></figure><p>Recently, <strong>WebRTC</strong> has become more preferred because of the deficiencies in the protocol support of browser-based applications. <strong>WebRTC</strong> provides real-time communication over peer-to-peer protocol. <strong>WebRTC</strong> protocol needs two browser client to communicate. Highly Available <strong>Janus Gateway</strong> easily configured and deployed on <strong>Kubernetes</strong> cluster. In the following architecture, if any of the <strong>Kubernetes</strong> Node fails, one of any other <strong>Kubernetes</strong> Node will take all responsibility. This allows us to build an <strong>Active-Passive</strong> High Availability Clustering architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*dsPlhjDF95fhveEKq8Bz2g.jpeg" /><figcaption>Architecture</figcaption></figure><h3>Janus Gateway</h3><p><strong>Janus Gateway</strong> is one of the first applications that you can act as a client and a server at the same time. As seen in the following two figures, both architecture explained. It is an open-source application implemented by <a href="https://www.meetecho.com/en/">Meetecho</a>. It provides a wide range of initiation protocol such as WebSocket and HTTP/HTTPS. In this blog, we will deploy Janus Gateway on Kubernetes with the configuration of a streaming plugin that supports stream video, audio, and data simultaneously over <strong>WebRTC</strong>. In addition, Janus has its own <a href="https://janus.conf.meetecho.com/docs/JS.html">JavaScript library</a> implementation that you could use in your web applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*5CRWXRytIYxeWkBx3mjerQ.png" /><figcaption><a href="https://www.meetecho.com/blog/wp-content/uploads/2018/10/streaming1.png">https://www.meetecho.com/blog/wp-content/uploads/2018/10/streaming1.png</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*E6kfRpQGp7A508zs3WPc9w.png" /><figcaption><a href="https://www.meetecho.com/blog/wp-content/uploads/2018/10/streaming2.png">https://www.meetecho.com/blog/wp-content/uploads/2018/10/streaming2.png</a></figcaption></figure><p>In Janus, each plugin has its own configuration and one for general purposes such as Real-time Transport Protocol (RTP) Port Range and NAT settings. The first configuration responsible for general configurations and the second one is responsible of Streaming Plugin configurations.</p><ul><li>janus.jcfg</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e95c3c4312babb76b9d241c717eb26fc/href">https://medium.com/media/e95c3c4312babb76b9d241c717eb26fc/href</a></iframe><ul><li>janus.plugin.streaming.jcfg</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5609f25d4ddc3e2f3927b338f7863d1/href">https://medium.com/media/c5609f25d4ddc3e2f3927b338f7863d1/href</a></iframe><p>In the streaming configuration, two-room created for streaming. For more detailed configuration explanations and examples, please visit <a href="https://github.com/meetecho/janus-gateway/blob/master/conf/janus.plugin.streaming.jcfg.sample.in">Janus Streaming Plugin Configuration Sample</a> and <a href="https://github.com/meetecho/janus-gateway/blob/master/conf/janus.jcfg.sample.in">Janus Configuration Sample</a>.</p><h3>Nginx</h3><p><strong>Nginx</strong> is a high-performance Proxy and Load Balancer application used by a wide range of people.</p><p><strong>Just Hint:</strong> besides UDP and TCP support, <strong>Nginx</strong> also supports higher-level load balancing like gRPC in HTTP v2.</p><p><strong>Nginx</strong> will be used as Load Balancer. The following configuration will be mounted as <strong>Kubernetes ConfigMap</strong> on <strong>Nginx Kubernetes</strong> Deployment.</p><ul><li>nginx.conf</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26ee334d033a017a19615c616971b9ba/href">https://medium.com/media/26ee334d033a017a19615c616971b9ba/href</a></iframe><p>In this configuration, assume that you have three <strong>Kubernetes Node</strong>. If you implement your own session distribution, then you can distribute without a backup option in this configuration.</p><h3>Kubernetes</h3><p>In this section, all configurations will be turned into <strong>Kubernetes</strong> YAMLs. We will repeat, but we will have to convert the above configurations by fitting the <strong>Kubernetes</strong> structure for ease of deployment. <strong>Janus Gateway</strong> and <strong>Coturn</strong> servers will be deployed as <strong>Kubernetes</strong> <strong>Daemonset</strong> and <strong>Nginx </strong>will be deployed as <strong>Kubernetes Deployment</strong>. Every <strong>Kubernetes</strong> <strong>Deployment</strong> and <strong>Kubernetes</strong> <strong>Daemonset</strong> has “not-ready” and “unreachable” toleration will be 0 to <strong>Kubernetes</strong> react fast as possible.</p><p><strong>Important Note:</strong> STUN will be used in this deployment. If your service will be served over NAT or a Firewall, you should use TURN server instead.</p><h4>Janus Gateway Deployment</h4><ul><li>ConfigMap</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f784bfc7b87ff928baab014978581555/href">https://medium.com/media/f784bfc7b87ff928baab014978581555/href</a></iframe><ul><li>Service</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb058d6a07cdf30941bd63efd744e0da/href">https://medium.com/media/fb058d6a07cdf30941bd63efd744e0da/href</a></iframe><ul><li>Deployment</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3926562bfb643b52aa942411f02eb9d/href">https://medium.com/media/e3926562bfb643b52aa942411f02eb9d/href</a></iframe><h4>Nginx Deployment</h4><ul><li>Configmap</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5729f4eddd584d085ee654fa2d4f6f9f/href">https://medium.com/media/5729f4eddd584d085ee654fa2d4f6f9f/href</a></iframe><ul><li>Service</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89e6fa6ba9470a77708af7e94a157c28/href">https://medium.com/media/89e6fa6ba9470a77708af7e94a157c28/href</a></iframe><ul><li>Deployment</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5a89490684350a9f592dfc5ae6fce82/href">https://medium.com/media/e5a89490684350a9f592dfc5ae6fce82/href</a></iframe><h4>Coturn Deployment</h4><ul><li>Service</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83f0f330bf25889acb3ddccc3f612d20/href">https://medium.com/media/83f0f330bf25889acb3ddccc3f612d20/href</a></iframe><ul><li>Deployment</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1c19d5a874bfcdd14456dc7ef43ce10/href">https://medium.com/media/b1c19d5a874bfcdd14456dc7ef43ce10/href</a></iframe><p>After applying these YAMLs with <strong>kubectl</strong>, we are done :)</p><p>Be careful about the installation sequence. The following sequence will be just fine.</p><p>1- Coturn</p><p>2- Janus Gateway</p><p>3- Nginx</p><h3>Conclusion</h3><p>This deployment provides us an Active-Passive Highly Available Janus Gateway cluster. With the help of <strong>Nginx</strong> Load Balancer, you can apply Active-Passive architectures to all your other applications using this methodology.</p><p><a href="https://www.ffmpeg.org/"><strong>ffmpeg</strong></a> or <a href="https://gstreamer.freedesktop.org/"><strong>gstreamer</strong></a> libraries could stream Video and Audio data to <strong>Janus Gateway</strong> streaming rooms. An application should be implemented to stream all three types of data at once.</p><p>This deployment could be turned into a <strong>Kubernetes Operator</strong> over <a href="https://helm.sh/"><strong>HELM</strong></a> in the future. After Kubernetes Operator is created, this could be submitted to <a href="https://operatorhub.io/"><strong>OperatorHub</strong></a>.</p><h3>References</h3><ul><li><a href="https://github.com/coturn/coturn"><em>Coturn</em></a></li><li><a href="https://github.com/meetecho"><em>Janus Gateway</em></a></li><li><a href="https://hub.docker.com/_/nginx"><em>Nginx</em></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2189256e5525" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenVPN Client in a Pod: Kubernetes]]></title>
            <link>https://bugraoz93.medium.com/openvpn-client-in-a-pod-kubernetes-d3345c66b014?source=rss-3eaa5ec9f16b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3345c66b014</guid>
            <category><![CDATA[bare-metal-cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[openvpn]]></category>
            <dc:creator><![CDATA[Bugra Ozturk]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 22:19:29 GMT</pubDate>
            <atom:updated>2020-05-01T05:59:31.219Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b7bXx94kEg8ajpPPUG5-Hg.png" /><figcaption><a href="https://openvpn.net/">OpenVPN</a> &amp; <a href="https://kubernetes.io/">Kubernetes</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>Connecting applications or machines to a VPN (Virtual Private Network) is a commonly used method to make secure communications between two networks. Note that, described solution is not part of site to site VPN solutions. Also, the solution is directly deployed on Bare Metal Kubernetes with OpenVPN Client. While we redirect all of our Kubernetes&#39; Pods network traffic through a specific OpenVPN Server, we protect our Kubernetes Networking.</p><p>First of all, every pod in your cluster can connect different VPN Serves. The most important side of this solution is the flexibility to manage your resources without managing persistent OpenVPN Client hosts and distribute them from Kubernetes. Also, after connecting a pod to OpenVPN Server, your pod still will be communicating with your Kubernetes Services and Resources.</p><p><strong>It can provide</strong></p><ul><li>a secure communication between your pod and your cloud service(s) and instance(s).</li><li>a secure communication between your resource(s) located in headquarter(s) and your resource(s) from subsidiary office(s).</li><li>a secure jump host solution for managing resource(s) in different location(s) and region(s). (For docker solution visit <a href="https://medium.com/u/fbedb8ec4988">Eren Manış</a>’s <a href="https://medium.com/@manis.eren/ssh-to-intranet-through-a-jumphost-vpn-container-3d58c3af1761">Solution</a>)</li><li>a secure and untraceable connection to the internet.</li></ul><p>Following image describes the general architecture of this use cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kA8LNLdD6qW5ps25v0X_eQ.png" /><figcaption>Architecture</figcaption></figure><p>Due to Kubernetes Networking, it provides container-to-container communication like they are in the same host. Every container can reach any other container from localhost. For more information about networking in Kubernetes please read following documentation of Kubernetes. <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/network/networking.md#container-to-container">Networking Document on Github</a>.</p><p>It provides a simple networking architecture inside a pod.</p><ul><li>Container inside the pod connects to a OpenVPN Server</li><li>All the containers connect to the same OpenVPN Server directly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*Y8pZiFh-RSeKIgpqJRoEbQ.png" /><figcaption>Pod Architecture</figcaption></figure><p>OpenVPN Server deployment is not included because there are a lot of articles about this deployment process. If you want to reach cloud or bare metal deployment of OpenVPN Server, pleases visit the following <a href="https://openvpn.net/vpn-server-resources/">OpenVPN Documentation</a>. You can easily find the solution that fits your use cases such as cloud environments with BYOL (Bring Your Own License)licencing method.</p><h3>Kubernetes</h3><p>There are some points before we start the deployment.</p><ol><li>Version Compatibility</li><li>ConfigMap Read Only (Permission Denied to execute script)</li><li>OpenVPN Routing</li></ol><h4>Version Compatibility</h4><p>Following Deployment YAML can be used after Kubernetes v1.16. Because of the changes in the Kubernetes API, we have to migrate our old Deployments to the new ones. It affects API versions with apps/v1 and we have to define selector in our deployment specs.</p><blockquote><em>After </em><em>Kubernetes v1.16, Deployment in the </em><strong><em>extensions/v1beta1</em></strong><em>, </em><strong><em>apps/v1beta1</em></strong><em>, and </em><strong><em>apps/v1beta2</em></strong><em> API versions is no longer served</em></blockquote><p>Please read the <a href="https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/">Vallery Lancey (Lyft)’s blog</a> about API deprecation and converting old API objects to new API objects.</p><h4>ConfigMap Read Only</h4><p>ConfigMaps in Kubernetes are mounted as Read Only mode by default and container cannot execute scripts even though the default user is <em>root (privileged: true)</em>. We have a workaround with InitContainer config by mounting empty volume. It is done due to security reasons. For more information about it, please visit <a href="https://github.com/kubernetes/kubernetes/pull/58720">joelsmith’s PR.</a></p><h4>OpenVPN Routing</h4><p>OpenVPN Client oppresses all of the default routing on Kubernetes Pod. It prevents the communications between client side (Kubernetes Services and Hosts in Local Area) and client itself. It only matters when your OpenVPN Server or OpenVPN Client configuration redirects all traffic through OpenVPN Server. I would like to thank <a href="https://medium.com/u/fbedb8ec4988">Eren Manış</a> for a pair debugging session.</p><h4>Deployment</h4><p>Let’s explain the OpenVPN Client deployment on Bare Metal Kubernetes.</p><p>Ingredients:</p><ul><li><a href="https://github.com/dperson/openvpn-client">dperson/openvpn-client</a> image</li><li>ConfigMap (The Script to override the Routing)</li><li>2 x Secret (*.ovpn file, auth.txt file)</li><li>Deployment</li></ul><p>First we create our Secret. The <em>*.ovpn</em> file that contains OpenVPN Client side configurations and certificate and the <em>auth.txt</em> file should contain username line and password line that is defined to OpenVPN Server.</p><p>Sample auth.txt:</p><pre>username<br>password</pre><p>Creating Secrets:</p><pre>kubectl create secret generic vpn-config --from-file=client.ovpn<br>kubectl create secret generic vpn-auth --from-file=auth.txt</pre><p>ConfigMap 10routeconfig.yaml:</p><pre>kind: ConfigMap<br>metadata:<br>  name: route-script<br>apiVersion: v1<br>data:<br>  route-override.sh: |-<br>     #!/bin/sh<br>     VPN_GATEWAY=$(route -n | awk &#39;NR==3&#39; | awk &#39;{ print $2 }&#39;)<br>     ip route del 0.0.0.0/1 via $VPN_GATEWAY<br>     echo &quot;Route Updated&quot;</pre><p>Apply ConfigMap:</p><pre>kubectl apply -f 10routeconfig.yaml</pre><p>Deployment 20deployment.yaml:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: openvpn-client<br>spec:<br>  selector:<br>    matchLabels:<br>      app: openvpn-client<br>      vpn: vpn-id<br>  replicas: 1<br>  template:<br>    metadata:<br>      labels:<br>        app: openvpn-client<br>        vpn: vpn-id<br>    spec:<br>      volumes:<br>        - name: vpn-config<br>          secret:<br>            secretName: vpn-config<br>            items:<br>                - key: client.ovpn<br>                  path: client.ovpn<br>        - name: vpn-auth<br>          secret:<br>            secretName: vpn-auth<br>            items:<br>                - key: auth.txt<br>                  path: auth.txt<br>        - name: route-script<br>          configMap:<br>            name: route-script<br>            items:<br>              - key: route-override.sh<br>                path: route-override.sh<br>        - name: tmp<br>          emptyDir: {}<br>      initContainers:<br>      - name: vpn-route-init<br>        image: busybox<br>        command: [&#39;/bin/sh&#39;, &#39;-c&#39;, &#39;cp /vpn/route-override.sh /tmp/route/route-override.sh; chown root:root /tmp/route/route-override.sh; chmod o+x /tmp/route/route-override.sh;&#39;]<br>        volumeMounts:<br>          - name: tmp<br>            mountPath: /tmp/route<br>          - name: route-script<br>            mountPath: /vpn/route-override.sh<br>            subPath: route-override.sh<br>      containers:<br>        - name: vpn<br>          image: dperson/openvpn-client<br>          command: [&quot;/bin/sh&quot;,&quot;-c&quot;]<br>          args: [&quot;openvpn --config &#39;vpn/client.ovpn&#39; --auth-user-pass &#39;vpn/auth.txt&#39; --script-security 3 --route-up /tmp/route/route-override.sh;&quot;]<br>          stdin: true<br>          tty: true<br>          securityContext:<br>            privileged: true<br>            capabilities:<br>              add:<br>                - NET_ADMIN<br>          env:<br>            - name: TZ<br>              value: &quot;Turkey&quot;<br>          volumeMounts:<br>            - name: vpn-config<br>              mountPath: /vpn/client.ovpn<br>              subPath: client.ovpn<br>            - name: vpn-auth<br>              mountPath: /vpn/auth.txt<br>              subPath: auth.txt<br>            - name: tmp<br>              mountPath: /tmp/route<br>        - name: app1<br>          image: python:3.6-stretch<br>          command:<br>            - sleep<br>            - &quot;100000&quot;<br>          tty: true<br>      dnsConfig:<br>        nameservers:<br>          - 8.8.8.8<br>          - 8.8.4.4</pre><p>OpenVPN Command has some extended parameters. For the explanation of these parameters please visit <a href="https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/">Reference Manual for </a><a href="https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/">OpenVPN 2.4</a>.</p><h3><strong>Conclusion</strong></h3><p>Secure connection over some infrastructures like VPN is very useful in certain use cases. These are generally about secure communications between our service(s) in different region(s).</p><p>To sum it up, the solution covers some of the use cases in this area. We learn how to deploy OpenVPN Client on Bare Metal Kubernetes while we persist our Kubernetes Networking.</p><p>For further enhancement, you can reduce your Kubernetes YAMLs by creating your own docker image that includes routing-script.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3345c66b014" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One SSL, One Domain with Multiple Services: HAproxy on Kubernetes]]></title>
            <link>https://bugraoz93.medium.com/one-ssl-one-domain-with-multiple-services-haproxy-on-kubernetes-a026d733a9cb?source=rss-3eaa5ec9f16b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a026d733a9cb</guid>
            <category><![CDATA[haproxy]]></category>
            <category><![CDATA[bare-metal-cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[load-balancing]]></category>
            <dc:creator><![CDATA[Bugra Ozturk]]></dc:creator>
            <pubDate>Sat, 04 Apr 2020 18:07:50 GMT</pubDate>
            <atom:updated>2020-04-19T21:19:47.803Z</atom:updated>
            <content:encoded><![CDATA[<p>Today’s systems depends on multiple services with multiple back-ends. Also, in micro-service architecture, there are multiple services that front-end have to be communicate. This problem can be solved with multiple domain and multiple SSL bind to them but there is a solution that require less cost and maintenance over domains and their SSLs.</p><p>When handling lots of clients and lots of services, we have to use more reliable and highly available tools in our infrastructure. Kubernetes and HAProxy one of the most reliable and highly available tools in industry. Following architecture help you to reduce managing these connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*HeOzlIzSusDdTRc3ceUV8A.png" /><figcaption><strong>Architecture</strong></figcaption></figure><p>This architecture provide, communication between your front-end Apps and multiple service on your company, this architecture reduce workload and cost of your system. HAProxy terminates SSL communication and provide communication with multiple services over one SSL.</p><p>Solutions is Reverse Proxy with SSL termination on HAproxy. Following solution deployed on bare metal Kubernetes. This means that if you deploy this solution on cloud, you can use <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress">Load Balancer</a> instead of <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport">NodePort</a> to get more dynamism.</p><h3>HAProxy</h3><p>HAproxy is one of the most widely used Highly Available Load Balancer software over TCP&amp;HTTP. It is fast, reliable and open-source :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/0*lui0ENStItzE4oeH.png" /><figcaption><a href="http://www.haproxy.org/">http://www.haproxy.org/</a></figcaption></figure><p>For more information about HAProxy and it’s features please visit following link: <a href="http://www.haproxy.org/">HAProxy</a></p><h4>HAProxy Configurations</h4><p>HAProxy manages all of it configuration from a file called haproxy.cfg. Current stable version is HAProxy 2.1-stable. Documentation of latest stable version of haproxy about configuration can be reach from <a href="http://cbonte.github.io/haproxy-dconv/2.1/configuration.html">HAProxy Configurations</a>.</p><p>First of all our SSL file must be ready for HAProxy. How can we make ready our SSL for HAProxy. There are multiple file type for SSL certificate such as p12, crt and key or jks for Java.</p><p>Following commands describe how to convert file to file.</p><ul><li><strong>jks to p12</strong></li></ul><pre>keytool -importkeystore -srckeystore filename.jks -destkeystore filename.p12 -srcstoretype jks -deststoretype pkcs12</pre><ul><li><strong>p12 to crt and key</strong></li></ul><pre>openssl pkcs12 -in filename.p12 -nocerts -out filename.key<br>openssl pkcs12 -in filename.p12 -clcerts -nokeys -out filename.crt</pre><ul><li><strong>key to key without passphrase</strong></li></ul><pre>openssl rsa -in filename.key -out filename.key</pre><ul><li><strong>key and crt to HAProxy ready pem</strong></li></ul><pre>sudo cat filename.crt filename.key \<br>           | sudo tee filename.pem</pre><p>Our pem file is ready to read by HAProxy.</p><ul><li><strong>haproxy.cfg</strong></li></ul><pre>#haproxy.cfg</pre><pre>#provide statistical monitoring of services routed on HAProxy<br>listen stats<br>    bind *:30090<br>    mode http<br>    timeout connect 10s<br>    timeout client 30s<br>    timeout server 30s<br>    option forwardfor<br>    option httpclose<br>    stats enable<br>    stats show-legends<br>    stats refresh 5s<br>    stats uri /stats<br>    stats realm Haproxy\ Statistics<br>    stats auth username:pass # Username and Password for stats page<br>    stats admin if TRUE</pre><pre># provide global configuration to prevent configuration duplication<br>global<br>   maxconn 50000<br>   tune.ssl.default-dh-param 2048</pre><pre>#provide default configurations for defined frontend and backend configurations</pre><pre>defaults<br>    timeout connect 10s<br>    timeout client 100s<br>    timeout server 100s<br>    log global</pre><pre># provide configuration to connection from clients</pre><pre>frontend https-in<br>   bind *:443 ssl crt /usr/local/etc/haproxy/filename.pem<br>   mode http<br>   redirect scheme https if !{ ssl_fc }</pre><pre>acl uri_service1 path_beg /objectdetection<br>use_backend databossobjectdetectionservice if uri_service1</pre><pre>acl uri_service2 path_beg /superresolution<br>use_backend databosssuperresolutionservice if uri_service2</pre><pre>acl uri_service3 path_beg /textsummary<br>use_backend databosstextsummarizationservice uri_service3</pre><pre>acl uri_service4 path_beg /videoanomaly<br>use_backend databossvideoanomalyservice if uri_service4</pre><pre>default_backend databosswebservice</pre><pre>#provide configuration to load balance servers</pre><pre>backend databossobjectdetectionservice<br>   mode http<br>   balance     roundrobin<br>   server      objectdetectionserviceapp1 IP:Port check<br>   server      objectdetectionserviceapp2 IP:Port check<br>   server      objectdetectionserviceapp3 IP:Port check</pre><pre>backend databosssuperresolutionservice<br>   mode http<br>   balance     roundrobin<br>   server      ssuperresolutionserviceapp1 IP:Port check<br>   server      ssuperresolutionserviceapp2 IP:Port check<br>   server      ssuperresolutionserviceapp3 IP:Port check</pre><pre>backend databosstextsummarizationservice<br>   mode http<br>   balance     roundrobin<br>   server      textsummarizationserviceapp1 IP:Port check<br>   server      textsummarizationserviceapp2 IP:Port check<br>   server      textsummarizationserviceapp3 IP:Port check</pre><pre>backend databossvideoanomalyservice<br>   mode http<br>   balance     roundrobin<br>   server      videoanomalyserviceapp1 IP:Port check</pre><pre>backend databosswebservice<br>   mode http<br>   balance     roundrobin<br>   server      webserviceapp1 IP:port check<br>   server      webserviceapp2 IP:port check</pre><p>More information about essentials of haproxy configuration could be read from a <a href="https://www.haproxy.com/blog/the-four-essential-sections-of-an-haproxy-configuration/">Chad Lavoie’s blog</a>.</p><h3>Kubernetes</h3><p>Deployment of HAProxy on Bare Metal Kubernetes will introduce as Deployment, NodePort, ConfigMap and Secret.</p><p>We apply ConfigMap will hold <em>haproxy.cfg and </em><em>Secret</em> will hold<em> api.pem </em>files. When configurations persisted on Kubernetes environment, it provide flexibility that statefull apps could act as stateless that automatically deployed on any cluster node.</p><p>First we have to create our ConfigMap and Secret with following commands.</p><pre>kubectl create cm haproxy-cfg --from-file=haproxy.cfg<br>kubectl create secret generic api-ssl --from-file=filename.pem</pre><p>There will be two NodePort for <strong><em>stats page: *:30090</em></strong> and for <strong><em>HTTPS endpoint: *:443</em></strong>.</p><ul><li>haproxy-svc.yaml</li></ul><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: haproxy-svc<br>spec:<br>  selector:<br>    app: databoss-haproxy<br>  type: NodePort<br>  ports:<br>  - name: https<br>    port: 443<br>    nodePort: 30443</pre><ul><li>haproxy-stats-svc.yaml</li></ul><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: haproxy-stats-svc<br>spec:<br>  selector:<br>    app: databoss-haproxy<br>  type: NodePort<br>  ports:<br>  - name: http<br>    port: 30090<br>    nodePort: 31090</pre><p>Now we apply services.</p><pre>kubectl apply -f haproxy-svc.yaml<br>kubectl apply -f haproxy-stats-svc.yaml</pre><p>After creating services on Kubernetes, we are ready to apply our Deployment .</p><p><strong>Note: </strong>Following Deployment YAML can be used after Kubernetes v1.16. Because of the changes in Kubernetes API, we have to migrate our old Deployments to new Deployments. This added to apps/v1 and we have to writeselector in our deployment specs.</p><blockquote>After <em>Kubernetes v1.16</em>, Deployment in the <strong>extensions/v1beta1</strong>, <strong>apps/v1beta1</strong>, and <strong>apps/v1beta2</strong> API versions is no longer served</blockquote><p>Please read the <a href="https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/">Vallery Lancey (Lyft)’s blog</a> about API deprecation and converting old API objects to new API objects.</p><ul><li>haproxy.yaml</li></ul><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: databoss-haproxy<br>spec:<br>  selector:<br>    matchLabels:<br>      app: databoss-haproxy<br>  replicas: 1<br>  template:<br>    metadata:<br>      labels:<br>        app: databoss-haproxy<br>    spec:<br>      volumes:<br>        - name: ha-volume<br>          configMap:<br>            name: haproxy-cfg<br>            items:<br>                - key: haproxy.cfg<br>                  path: haproxy.cfg<br>        - name: ha-ssl<br>          secret:<br>            secretName: api-ssl<br>            items:<br>                - key: filename.pem<br>                  path: filename.pem<br>      containers:<br>        - image: haproxy<br>          name: haproxy<br>          volumeMounts:<br>            - name:  ha-volume<br>              mountPath: /usr/local/etc/haproxy/haproxy.cfg<br>              subPath: haproxy.cfg<br>            - name: ha-ssl<br>              mountPath: /usr/local/etc/haproxy/filename.pem<br>              subPath: filename.pem<br>          imagePullPolicy: Always<br>          env:<br>          - name: TZ<br>            value: &quot;Turkey&quot;</pre><p>Now we apply deployment.</p><pre>kubectl apply -f haproxy.yaml</pre><p>It’s done!!!</p><h3>Conclusion</h3><p>We deploy HAProxy on Kubernetes that handles multiple services over one domain and one SSL. It reduce our workload to manage&amp;maintain multiple domain and SSL. Also, we have the power of highly available Load Balancer and highly available orchestration service to reduce downtime of our services.</p><p>In this article, we learn how we could provide communication between our Client and all our different kind of services on different environments with <strong>Only One Domain&amp;SSL</strong>.</p><p>In Kubernetes HAProxy deployment, <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/">Kubernetes RBAC</a> can be integrated. It could provide authorization layer on Kubernetes within your organization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a026d733a9cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>