<?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 Lightphos on Medium]]></title>
        <description><![CDATA[Stories by Lightphos on Medium]]></description>
        <link>https://medium.com/@lightphos?source=rss-b8e9a3e517f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bh3JT4buzkc-eOaqNBiIow.png</url>
            <title>Stories by Lightphos on Medium</title>
            <link>https://medium.com/@lightphos?source=rss-b8e9a3e517f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 23:58:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lightphos/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[Load balancing, Session Affinity and Observability with Istio on WSL2 Ubuntu and Docker Desktop]]></title>
            <link>https://medium.com/actual-tech/load-balancing-session-affinity-and-observability-with-istio-on-wsl2-ubuntu-and-docker-desktop-362222f62225?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/362222f62225</guid>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kiali]]></category>
            <category><![CDATA[wsl-2]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[load-balancing]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Fri, 02 Jul 2021 10:15:13 GMT</pubDate>
            <atom:updated>2024-01-18T17:37:42.477Z</atom:updated>
            <content:encoded><![CDATA[<p>See also updated video version here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLWlcnYE_XXA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLWlcnYE_XXA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLWlcnYE_XXA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc1873f5ddedd04ef20edd74c904ad31/href">https://medium.com/media/cc1873f5ddedd04ef20edd74c904ad31/href</a></iframe><p>In this article we look at Istio’s load balancing features plus the Kiali and Grafana add ons.</p><p>We will be using WSL2 Ubuntu 20.04, in Windows 10, Docker Desktop with Kubernetes and K9s.</p><p>Assuming you already have WSL2 and Ubuntu 20.04 installed.</p><h4>Getting Started</h4><p>Start Docker desktop (see link below for how to install).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mZNpuc8T2b-n7Ns5AvJDqw.png" /></figure><p>Docker engine is v20.10.6, enable Kubernetes. Takes a while to start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-O4Axx2nS8jcvuaKFtqw1A.png" /></figure><p>Check versions in wsl2 ubuntu:</p><p>Ubuntu</p><pre>cat /etc/*release<br>DISTRIB_ID=Ubuntu<br>DISTRIB_RELEASE=20.04<br>DISTRIB_CODENAME=focal<br>DISTRIB_DESCRIPTION=&quot;Ubuntu 20.04.2 LTS&quot;<br></pre><p>Docker</p><pre>docker version<br>Client: Docker Engine - Community<br> Cloud integration: 1.0.14<br> Version:           20.10.6<br> API version:       1.41<br> Go version:        go1.13.15<br> Git commit:        370c289<br> Built:             Fri Apr  9 22:46:45 2021<br> OS/Arch:           linux/amd64<br> Context:           default<br> Experimental:      true</pre><p>Kubectl</p><pre>kubectl version<br>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;19&quot;, GitVersion:&quot;v1.19.7&quot;, GitCommit:&quot;1dd5338295409edcfff11505e7bb246f0d325d15&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-01-13T13:23:52Z&quot;, GoVersion:&quot;go1.15.5&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}<br>Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;19&quot;, GitVersion:&quot;v1.19.7&quot;, GitCommit:&quot;1dd5338295409edcfff11505e7bb246f0d325d15&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-01-13T13:15:20Z&quot;, GoVersion:&quot;go1.15.5&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}</pre><p><strong>Install k9s</strong></p><p>A useful tool to manage the cluster (there is also Lens, see link below).</p><pre>sudo curl -ssL <a href="https://gist.githubusercontent.com/bplasmeijer/a4845a4858f1c0b0a22848984475322d/raw/0768fa37a96a319f7e784e77ba24a085fe527369/k9s-setup.sh">https://gist.githubusercontent.com/bplasmeijer/a4845a4858f1c0b0a22848984475322d/raw/0768fa37a96a319f7e784e77ba24a085fe527369/k9s-setup.sh</a> | sudo sh</pre><p><strong>Echo Server Image</strong></p><p>Our test image to deploy.</p><pre>docker pull inanimate/echo-server</pre><pre>kubectl create deployment echo-server --image=inanimate/echo-server<br>deployment.apps/echo-server created</pre><p>in k9s default namespace</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1U9v17GWWT-P4bv7cprKCg.png" /></figure><p>Please l for logs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNewPpYvSO93N-Xzd5khPg.png" /></figure><p><strong>Port Forward</strong></p><p>With k9s</p><p>select pod view :po, select pod, select container</p><p>Press Shift-f, define ports</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3sk7U3g8aQTF81fH0Y57hQ.png" /></figure><p>Navigate to it:</p><p><a href="http://localhost:8080/">http://localhost:8080</a></p><pre>Welcome to echo-server!  Here&#39;s what I know.<br>  &gt; Head to /ws for interactive websocket echo!<br><br>-&gt; My hostname is: echo-server-f5666cc48-k5hlr</pre><p>:pf to view it and ctrl-d to delete the port forward</p><p>Create echo service layer in kubernetes</p><pre>echo &quot;<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: echo-server<br>spec:<br>  ports:<br>    - port: 80<br>      protocol: TCP<br>      targetPort: 8080<br>  selector:<br>    app: echo-server<br>&quot; | kubectl apply -f -</pre><p>Echo-server is now available as a service.</p><p>Now lets add Istio…</p><h3><strong>Istioctl</strong></h3><p>Install it:</p><pre>curl -L <a href="https://istio.io/downloadIstio">https://istio.io/downloadIstio</a> | sh -</pre><pre>export PATH=”$PATH:/mnt/c/Users/&lt;&gt;/istio-1.10.2/bin”</pre><pre>istioctl x precheck</pre><pre>istioctl version</pre><pre>1.10.2</pre><p>istioctl install</p><pre>This will install the Istio 1.10.2  profile with [&quot;Istio core&quot; &quot;Istiod&quot; &quot;Ingress gateways&quot;] components into the cluster. Proceed? (y/N) y<br>✔ Istio core installed<br>✔ Istiod installed<br>✔ Ingress gateways installed<br>✔ Installation complete</pre><p>Add the addons</p><pre>kubectl apply -f /mnt/c/Users/&lt;&gt;/istio-1.10.2/samples/addons</pre><p>Install of kiali may spit out “no matches for kind…” just ignore.</p><p>Enable istio injection for default namespace (in a true deployment you would want your own separate namespace for your services)</p><pre>kubectl label namespace default istio-injection=enabled</pre><p>Delete the existing pod for echo-server container so it restarts with the istio/envoy side car containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W02kTBvRMAafvXUWnYjctA.png" /></figure><p>It will now restart with the side car proxy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G34chP48iREqzRJ7Bseqww.png" /></figure><p>Check out the istio services :ns istio-system :svc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFAhWfPspiNsJF3mrR57Kw.png" /></figure><p>Configure the gateway</p><pre>echo &quot;<br>apiVersion: networking.istio.io/v1alpha3<br>kind: Gateway<br>metadata:<br>  name: echo-gateway<br>spec:<br>  selector:<br>    istio: ingressgateway <em># use istio default controller<br>  </em>servers:<br>    - port:<br>        number: 80<br>        name: http<br>        protocol: http<br>      hosts:<br>        - host.docker.internal<br>&quot; | kubectl apply -f -</pre><p>We are using the built in host.docker.internal (which points to local machine IP in the windows hosts file) set up by docker desktop.</p><p>Then add virtual service to this tying up the g/w host echo-gateway to the service in k8s echo-server.</p><pre>echo &quot; <br>apiVersion: networking.istio.io/v1alpha3<br>kind: VirtualService<br>metadata:<br>  name: echo-service-vs<br>  namespace: default<br>spec:<br>  hosts:<br>    - host.docker.internal<br>  gateways:<br>    - echo-gateway<br>  http:<br>    - route:<br>        - destination:<br>            host: echo-server.default.svc.cluster.local<br>            port:<br>              number: 80<br>&quot; | kubectl apply -f -</pre><p>Call our service via the g/w:</p><pre>curl -s host.docker.internal | grep host<br>-&gt; My hostname is: echo-server-f5666cc48-pp8tw<br> Host: host.docker.internal</pre><p>or</p><pre><a href="http://host.docker.internal/">http://host.docker.internal/</a></pre><p><strong>Scaling and Load balancing</strong></p><p>Scale the deployment, in k9s, :ns default, :dp, s , replicas change to 2 or more</p><p>Should start up extra pods each with istio side cars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2m38FFlLNCZr13GPFZW-5g.png" /></figure><p>Call the service again via the g/w:</p><pre>curl -s host.docker.internal | grep host</pre><pre>&gt; My hostname is: echo-server-f5666cc48-tss5c</pre><pre>curl -s host.docker.internal | grep host</pre><pre>&gt; My hostname is: echo-server-f5666cc48-vkt6v</pre><p>Load balancing in a round robin fashion hitting an alternative pod on each call.</p><p><strong>Stick Sessions (Session Affinity)</strong></p><p>In case you have a need to ensure all requests from a source go to the same server. Here we use the source IP, options are http header name (httpHeaderName), cookies (httpCookie) and others.</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: networking.istio.io/v1alpha3<br>kind: DestinationRule<br>metadata:<br>    name: echo-service-dr<br>spec:<br>    host: echo-server.default.svc.cluster.local<br>    trafficPolicy:<br>      loadBalancer:<br>        consistentHash:<br>          httpHeaderName: x-user<br>EOF</pre><p>Try calling:</p><pre>curl -s -H “x-user: anon” host.docker.internal | grep host<br>-&gt; My hostname is: echo-server-f5666cc48–6kxfb</pre><pre>curl -s -H “x-user: anon” host.docker.internal | grep host<br>-&gt; My hostname is: echo-server-f5666cc48–6kxfb</pre><p>Now it always hits the same one, on every request, a sticky session.</p><pre>curl -s -H “x-user: auser” host.docker.internal | grep host<br>-&gt; My hostname is: echo-server-f5666cc48-tss5c</pre><p>Try with</p><p>httpQueryParameterName</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: networking.istio.io/v1alpha3<br>kind: DestinationRule<br>metadata:<br>    name: echo-service-dr<br>spec:<br>    host: echo-server.default.svc.cluster.local<br>    trafficPolicy:<br>      loadBalancer:<br>        consistentHash:<br>          httpQueryParameterName: echoq<br>EOF</pre><p>Call with different parameters:</p><pre>curl -s host.docker.internal?echoq=test1 | grep host<br>-&gt; My hostname is: echo-server-f5666cc48-b2z8c</pre><pre>curl -s host.docker.internal?echoq=test2 | grep host<br>-&gt; My hostname is: echo-server-f5666cc48-gg44l</pre><p>The following other LB algorithms are available:</p><p>ROUND_ROBIN, LEAST_CONN, RANDOM, or PASSTHROUGH.</p><p>Lets try RANDOM</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: networking.istio.io/v1alpha3<br>kind: DestinationRule<br>metadata:<br>    name: echo-service<br>spec:<br>    host: echo-server.default.svc.cluster.local<br>    trafficPolicy:<br>      loadBalancer:<br>        simple: RANDOM<br>EOF</pre><p>Now get random servers for each request</p><pre>curl -s host.docker.internal | grep host<br>-&gt; My hostname is: echo-server-f5666cc48-vkt6v</pre><pre>curl -s host.docker.internal | grep host<br>-&gt; My hostname is: echo-server-f5666cc48-tss5c</pre><h4><strong>Observability/Stats</strong></h4><p><em>Note: To really see tracing and metrics, you need a service that sends tracing data to these services. See previous blog here for hooks in java spring </em><a href="https://levelup.gitconnected.com/observability-of-springboot-services-in-k8s-with-prometheus-and-grafana-61c4e7a9d814">https://levelup.gitconnected.com/observability-of-springboot-services-in-k8s-with-prometheus-and-grafana-61c4e7a9d814</a></p><p>Add some load to get some data, using apache benchmark</p><pre>ab -c 10 -n 100 host.docker.internal/ </pre><pre><br>This is ApacheBench, Version 2.3 &lt;$Revision: 1843412 $&gt;<br>Copyright 1996 Adam Twiss, Zeus Technology Ltd, <a href="http://www.zeustech.net/">http://www.zeustech.net/</a><br>Licensed to The Apache Software Foundation, <a href="http://www.apache.org/">http://www.apache.org/</a></pre><pre>Benchmarking host.docker.internal (be patient).....done</pre><pre>Server Software:        istio-envoy<br>Server Hostname:        host.docker.internal<br>Server Port:            80</pre><p><strong>Grafana</strong></p><pre>istioctl dashboard grafana</pre><p>Peaks are apache bench mark being run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RV63eyzMHQAKtVrFE0nk6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7aKFaPDDT8Xy8oiZw66Bw.png" /></figure><p><strong>Kiali</strong></p><p>Update Kialis configmap adding this to it:</p><pre>external_services:<br>  tracing:<br>     url: <a href="http://localhost:16686/">http://localhost:16686</a><br>     in_cluster_url: <a href="http://tracing.istio-system/jaeger">http://tracing.istio-system/jaeger</a><br>  grafana:<br>     url: http://localhost:3000<br>     in_cluster_url: <a href="http://grafana.istio-system/">http://grafana.istio-system</a><br> custom_dashboards:<br>    enabled: true</pre><p>Restart the kiali pod.</p><p>Start the dashboard</p><pre>istioctl dashboard kiali</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ne3sQOJynxKNaGLia50LYg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IhvMZFFGCvQzIgJs9cpppQ.png" /></figure><p><strong>Jaeger</strong></p><pre>istioctl dashboard jaeger</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hi2hxcn2rPhQLKix_fDwNA.png" /></figure><p>— -</p><p><strong>Conclusion</strong></p><p>There you go, k8s on WSL2 ubuntu and using Istio to provide load balanced session control with observability.</p><p><strong>See also:</strong></p><ul><li><a href="https://docs.docker.com/docker-for-windows/wsl/">Docker Desktop WSL 2 backend</a></li><li><a href="https://medium.com/actual-tech/istio-with-kubernetes-b898be1014d7">Istio with Kubernetes</a></li></ul><p><a href="https://istio.io/latest/docs/reference/config/networking/destination-rule/">https://istio.io/latest/docs/reference/config/networking/destination-rule/</a></p><ul><li><a href="https://dev.to/peterj/what-are-sticky-sessions-and-how-to-configure-them-with-istio-1e1a">What are sticky sessions and how to configure them with Istio?</a></li><li><a href="https://medium.com/flant-com/k9s-terminal-ui-for-kubernetes-aeead8b0303f">K9s — the powerful terminal UI for Kubernetes</a></li></ul><p>An alternative to K9s is:</p><p><a href="https://k8slens.dev/">Lens | The Kubernetes IDE</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=362222f62225" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/load-balancing-session-affinity-and-observability-with-istio-on-wsl2-ubuntu-and-docker-desktop-362222f62225">Load balancing, Session Affinity and Observability with Istio on WSL2 Ubuntu and Docker Desktop</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wiremock PDF File (Binary) Response with Spring Rest Template]]></title>
            <link>https://medium.com/actual-tech/wiremock-pdf-file-binary-response-with-spring-rest-template-e6d2928f2623?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6d2928f2623</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[wiremock]]></category>
            <category><![CDATA[gradle]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Mon, 07 Sep 2020 10:07:22 GMT</pubDate>
            <atom:updated>2024-02-22T18:10:33.111Z</atom:updated>
            <content:encoded><![CDATA[<h4>PROGRAMMING</h4><h3>Wiremock PDF File Response with Springs Rest Template</h3><h4>Wiremocking a PDF file can be tricky, here we see how to do so easily with Springs Test Rest Template</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s97yi6jnKMtYXrou.jpg" /><figcaption>Photo by <a href="https://unsplash.com/@yancymin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Yancy Min</a> on <a href="https://unsplash.com/s/photos/code?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fbv_h6V5qjW8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dbv_h6V5qjW8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fbv_h6V5qjW8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/078389d66cda35cb423f18e71e39bcd7/href">https://medium.com/media/078389d66cda35cb423f18e71e39bcd7/href</a></iframe><p>Wiremock <a href="http://wiremock.org/">http://wiremock.org/</a>, is a great tool to mock out real REST service dependencies to improve your integration testing without needing the full interdependent system in place.</p><p>In this specific example we look at how to very easily mock a REST call returning a PDF file using the execute method of the Spring Rest Template and basic wiremock constructs.</p><h3>Code</h3><p>The code will be written using spring boot and gradle.</p><h4><strong>Dependencies</strong></h4><pre>plugins {<br>    id &#39;application&#39;<br>    id &#39;org.springframework.boot&#39; version &#39;2.3.2.RELEASE&#39;<br>    id &#39;io.spring.dependency-management&#39; version &#39;1.0.8.RELEASE&#39;<br>}<br><br>mainClassName=&quot;org.example.wiremock.PDFClient&quot;<br><br>group &#39;org.example&#39;<br>version &#39;1.0-SNAPSHOT&#39;<br>sourceCompatibility = &#39;1.8&#39;<br><br>repositories {<br>    mavenCentral()<br>}<br><br>dependencies {<br>    implementation &#39;org.springframework.boot:spring-boot-starter-web:2.3.2.RELEASE&#39;<br>    testImplementation &#39;org.springframework.boot:spring-boot-starter-test:2.3.2.RELEASE&#39;<br>    testImplementation &#39;com.github.tomakehurst:wiremock-jre8:2.27.0&#39;<br>    testCompile  &#39;junit:junit:4.12&#39;<br>}</pre><h4><strong>Application</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/988e1db0cedcc9f0fa39e4064b1114db/href">https://medium.com/media/988e1db0cedcc9f0fa39e4064b1114db/href</a></iframe><p>The application makes a rest call to an external site to display a pdf.</p><h4><strong>Test</strong></h4><p>The test uses the wiremock rule and stub to mock the subsequent request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29124f207655b7aeff7a6e9ad5d74946/href">https://medium.com/media/29124f207655b7aeff7a6e9ad5d74946/href</a></iframe><p>On line 19, we replace the target host with local host as the embedded wiremock server will run on localhost of course.</p><p>On line 21, we set the stub for wiremock to match the path and the mocked response.</p><p>The interesting part is the template execute callbacks ‘requestCallback’ and ‘extract’.</p><p>These callbacks give us the flexibility using Springs TestRestTemplate to set up the request. If needed we can also map JSON objects more finely like so:</p><pre>ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(clientHttpRequest.getBody(), somevalue);</pre><p>In our case we just need to set the header.</p><p>The response callback gives us the ability to handle the resulting byte stream and simply convert it to string.</p><p>You can then invoke gradle test task to run this test and see the secondary REST call being mocked. Of course you can replace gradle with maven if you wish.</p><p>Notice how the wiremock part is only a couple of lines.</p><h3>Resources</h3><p>Complete source can found here:</p><p><a href="https://gitlab.com/lightphos/spring/wiremockpdf-tut/-/tree/master">https://gitlab.com/lightphos/spring/wiremockpdf-tut/-/tree/master</a></p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/wiremock-spring-and-binary/"><em>https://blog.ramjee.uk</em></a><em> on September 7, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6d2928f2623" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/wiremock-pdf-file-binary-response-with-spring-rest-template-e6d2928f2623">Wiremock PDF File (Binary) Response with Spring Rest Template</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Knative Eventing in Kubernetes with a Java Listener and Sender]]></title>
            <link>https://medium.com/actual-tech/simple-knative-eventing-in-kubernetes-with-a-java-listener-and-sender-d7e83766297b?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7e83766297b</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[eventing]]></category>
            <category><![CDATA[knative]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Wed, 19 Aug 2020 18:01:20 GMT</pubDate>
            <atom:updated>2020-08-19T18:21:20.766Z</atom:updated>
            <content:encoded><![CDATA[<h4>programming</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*Fp6BHbs65IyX9rwp.png" /></figure><p><a href="https://medium.com/@lightphos/knative-service-k8s-and-spring-java-538e269eee5f">Previously</a> we ran a service using Knative Server and kicked it off with a http request.</p><p>Here we will write our own Knative services that act on events a listener and a sender both in Java using Spring Boot.</p><h3>Set up</h3><p>Docker Desktop (macos) 2.3.03<br>K8s 1.16.5<br>Istio 1.6.4</p><h3>Install Eventing</h3><p>From <a href="https://knative.dev/development/install/any-kubernetes-cluster/#installing-the-eventing-component">https://knative.dev/development/install/any-kubernetes-cluster/#installing-the-eventing-component</a></p><p>Install the eventing components:</p><blockquote><strong><em>kubectl apply — filename </em></strong><a href="https://github.com/knative/eventing/releases/download/v0.16.0/eventing-crds.yaml"><strong><em>https://github.com/knative/eventing/releases/download/v0.16.0/eventing-crds.yaml</em></strong></a></blockquote><blockquote><em>customresourcedefinition.apiextensions.k8s.io/apiserversources.sources.knative.dev created<br>customresourcedefinition.apiextensions.k8s.io/brokers.eventing.knative.dev created<br>customresourcedefinition.apiextensions.k8s.io/channels.messaging.knative.dev created<br>etc</em></blockquote><blockquote><strong><em>kubectl apply — filename </em></strong><a href="https://github.com/knative/eventing/releases/download/v0.16.0/eventing-core.yaml"><strong><em>https://github.com/knative/eventing/releases/download/v0.16.0/eventing-core.yaml</em></strong></a></blockquote><blockquote><em>namespace/knative-eventing created<br>serviceaccount/eventing-controller created<br>clusterrolebinding.rbac.authorization.k8s.io/eventing-controller created<br>clusterrolebinding.rbac.authorization.k8s.io/eventing-controller-resolver created<br>clusterrolebinding.rbac.authorization.k8s.io/eventing-controller-source-observer created<br>clusterrolebinding.rbac.authorization.k8s.io/eventing-controller-sources-controller created<br>clusterrolebinding.rbac.authorization.k8s.io/eventing-controller-manipulator created<br>serviceaccount/pingsource-mt-adapter created<br>clusterrolebinding.rbac.authorization.k8s.io/knative-eventing-pingsource-mt-adapter created<br>serviceaccount/eventing-webhook created</em></blockquote><blockquote><em>etc</em></blockquote><h3>Istio Cluster Gateway</h3><p>This is needed for correct service discovery in Knative Eventing service startup.</p><pre>cat &lt;&lt; EOF &gt; ./istio-minimal-operator.yaml<br>apiVersion: install.istio.io/v1alpha1<br>kind: IstioOperator<br>spec:<br>  values:<br>    global:<br>      proxy:<br>        autoInject: disabled<br>      useMCP: false<br>      # The third-party-jwt is not enabled on all k8s.<br>      # See: https://istio.io/docs/ops/best-practices/security/#configure-third-party-service-account-tokens<br>      jwtPolicy: first-party-jwt<br><br>  addonComponents:<br>    pilot:<br>      enabled: true<br>    prometheus:<br>      enabled: false<br><br>  components:<br>    ingressGateways:<br>      - name: istio-ingressgateway<br>        enabled: true<br>      - name: cluster-local-gateway<br>        enabled: true<br>        label:<br>          istio: cluster-local-gateway<br>          app: cluster-local-gateway<br>        k8s:<br>          service:<br>            type: ClusterIP<br>            ports:<br>            - port: 15020<br>              name: status-port<br>            - port: 80<br>              name: http2<br>            - port: 443<br>              name: https<br>EOF</pre><blockquote><em>istioctl manifest apply -f istio-minimal-operator.yml</em></blockquote><h3>Event Display and Ping Source</h3><p>First we will use a pre-defined event display Service and Ping source.</p><pre>cat &lt;&lt;EOF | kubectl create -f -<br>apiVersion: serving.knative.dev/v1<br>kind: Service<br>metadata:<br>  name: event-display<br>spec:<br>  template:<br>    spec:<br>      containers:<br>        - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display<br>EOF</pre><blockquote><em>kn service list<br>NAME URL LATEST AGE CONDITIONS READY REASON<br>event-display </em><a href="http://event-display.default.example.com/"><em>http://event-display.default.example.com</em></a><em> 7s 0 OK / 3 Unknown RevisionMissing : Configuration “event-display” is waiting for a Revision to become ready.</em></blockquote><p>Let’s create a standard Ping Source</p><pre>cat &lt;&lt;EOF | kubectl create -f -<br>apiVersion: sources.knative.dev/v1alpha2<br>kind: PingSource<br>metadata:<br>  name: test-ping-source<br>spec:<br>  schedule: &quot;*/2 * * * *&quot;<br>  jsonData: &#39;{&quot;message&quot;: &quot;Hello world!&quot;}&#39;<br>  sink:<br>    ref:<br>      apiVersion: serving.knative.dev/v1<br>      kind: Service<br>      name: event-display<br>EOF</pre><p>This will send the message “Hello World” every two minutes.</p><blockquote><em>kn source list<br>NAME TYPE RESOURCE SINK READY<br>test-ping-source PingSource pingsources.sources.knative.dev ksvc:event-display True</em></blockquote><p>Check if the event display service is receiving events.</p><blockquote><em>kubectl logs -l serving.knative.dev/service=event-display -c user-container — since=10m</em></blockquote><blockquote><em>specversion: 1.0<br>type: dev.knative.sources.ping<br>source: /apis/v1/namespaces/default/pingsources/test-ping-source<br>id: c9270430-a649–4980–87a1-f9a7a985d2ac<br>time: 2020–08–05T00:32:00.003686838Z<br>datacontenttype: application/json<br>Data,<br>{<br>“message”: “Hello world!”<br>}</em></blockquote><p>You will see the pod being created and deleted which each ping (every 2 mins)</p><p>All good our Knative eventing services have been installed and are working.</p><p>Clean up</p><blockquote><em>kubectl delete pingsources.sources.knative.dev test-ping-source</em></blockquote><p>or</p><blockquote><em>kn source ping delete test-ping-source</em></blockquote><p>And also delete the event-display</p><blockquote><em>kn service delete event-display</em></blockquote><h3>Java Based Event Listener</h3><p>Let’s write our own event listener in Java, in kn-listener sub project.</p><pre>@Slf4j<br>@RestController<br>@SpringBootApplication<br>public class KnEventListener {<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(KnEventListener.class, args);<br>    }<br><br>    @GetMapping(value = &quot;/&quot;, produces = {MediaType.APPLICATION_JSON_VALUE})<br>    public ResponseEntity&lt;String&gt; status() {<br>        return ResponseEntity.ok(&quot;{\&quot;status\&quot;: \&quot;UP\&quot;}&quot;);<br>    }<br><br><br>    @PostMapping(value = &quot;/&quot;, consumes = {MediaType.APPLICATION_JSON_VALUE})<br>    public ResponseEntity&lt;Void&gt; event(@RequestHeader Map&lt;String, Object&gt; headers, @RequestBody String body) throws Exception {<br>        log.info(LocalDateTime.now() + &quot;, &quot; + body);<br>        return ResponseEntity.accepted().build();<br>    }<br><br>}</pre><p>build.gradle (parent)</p><pre>plugins {<br>    id &#39;org.springframework.boot&#39; version &#39;2.3.2.RELEASE&#39;<br>    id &quot;io.freefair.lombok&quot; version &quot;5.1.1&quot;<br>}<br><br><br>subprojects {<br><br>    group &#39;uk.co.vadalg&#39;<br>    version &#39;1.0-SNAPSHOT&#39;<br><br>    apply plugin: &#39;application&#39;<br>    apply plugin: &#39;org.springframework.boot&#39;<br>    apply plugin: &#39;io.spring.dependency-management&#39;<br>    apply plugin: &#39;io.freefair.lombok&#39;<br><br>    repositories {<br>        jcenter()<br>    }<br><br>}</pre><p>build.gradle (listener)</p><pre>mainClassName  = &quot;uk.co.ac.vadalg.KnEventListener&quot;<br><br>dependencies {<br>    implementation &#39;org.springframework.boot:spring-boot-starter-web&#39;<br>    implementation &#39;org.springframework.boot:spring-boot-starter-actuator&#39;<br>    implementation &#39;org.junit.jupiter:junit-jupiter:5.4.2&#39;<br>    testImplementation(&#39;org.springframework.boot:spring-boot-starter-test&#39;) {<br>        exclude group: &#39;org.junit.vintage&#39;, module: &#39;junit-vintage-engine&#39;<br>    }<br>}<br><br>test {<br>    useJUnitPlatform()<br>}<br><br>bootBuildImage {<br>    imageName = &#39;localhost:5007/kn-listener&#39;<br>}</pre><p>Create docker image (using gradle)</p><blockquote><em>gradle bootBuildImage</em></blockquote><p>then push to local docker registry and create the service (see <a href="https://medium.com/@lightphos/knative-service-k8s-and-spring-java-538e269eee5f">previous blog</a>)</p><blockquote><em>docker push localhost:5007/kn-listener</em></blockquote><blockquote>kn service create knlistener — image localhost:5007/<em>kn-listener</em></blockquote><p>If you have docker image connection issues you may need to check you have edited the configmap (see <a href="https://medium.com/@lightphos/knative-service-k8s-and-spring-java-538e269eee5f">previous blog</a> )</p><p>Test if the service is up:</p><blockquote><em>curl -i -H “Host: knlistener.default.example.com” localhost<br>HTTP/1.1 200 OK<br>content-length: 16<br>content-type: application/json<br>date: Thu, 06 Aug 2020 22:27:39 GMT<br>x-envoy-upstream-service-time: 5<br>server: istio-envoy</em></blockquote><blockquote><em>{“status”: “UP”}</em></blockquote><p>Start the ping again but this time referencing knlistener</p><pre>cat &lt;&lt;EOF | kubectl create -f -<br>apiVersion: sources.knative.dev/v1alpha2<br>kind: PingSource<br>metadata:<br>  name: test-ping-source<br>spec:<br>  schedule: &quot;*/2 * * * *&quot;<br>  jsonData: &#39;{&quot;message&quot;: &quot;Hi earth!&quot;}&#39;<br>  sink:<br>    ref:<br>      apiVersion: serving.knative.dev/v1<br>      kind: Service<br>      name: knlistener<br>EOF</pre><p>Check the logs</p><blockquote><em>kubectl logs -l serving.knative.dev/service=knlistener -c user-container — since=10m</em></blockquote><pre>2020-08-06 22:32:03.778  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext<br>2020-08-06 22:32:03.778  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1073 ms<br>2020-08-06 22:32:04.052  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService &#39;applicationTaskExecutor&#39;<br>2020-08-06 22:32:04.271  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path &#39;/actuator&#39;<br>2020-08-06 22:32:04.329  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path &#39;&#39;<br>2020-08-06 22:32:04.342  INFO 1 --- [           main] uk.co.ac.vadalg.KnEventListener          : Started KnEventListener in 2.058 seconds (JVM running for 2.479)<br>2020-08-06 22:32:04.544  INFO 1 --- [nio-8080-exec-3] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet &#39;dispatcherServlet&#39;<br>2020-08-06 22:32:04.545  INFO 1 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Initializing Servlet &#39;dispatcherServlet&#39;<br>2020-08-06 22:32:04.550  INFO 1 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Completed initialization in 5 ms<br>2020-08-06 22:32:04.641  INFO 1 --- [nio-8080-exec-3] uk.co.ac.vadalg.KnEventListener          : 2020-08-06T22:32:04.641, {&quot;message&quot;:&quot;Hi earth!&quot;}</pre><p>Boing, spring event listener. Nice.</p><p>Delete the test source</p><blockquote><em>kn source ping delete test-ping-source</em></blockquote><p>Can also test the kn service listener with a curl pod:</p><pre>kubectl run curl \<br>    --image=curlimages/curl --rm=true --restart=Never -ti -- \<br>    -X POST -v \<br>    -H &quot;content-type: application/json&quot;  \<br>    -H &quot;ce-specversion: 1.0&quot;  \<br>    -H &quot;ce-source: http://curl-command&quot;  \<br>    -H &quot;ce-type: curl.demo&quot;  \<br>    -H &quot;ce-id: ekbetron&quot;  \<br>    -d &#39;{&quot;name&quot;:&quot;lightphos&quot;}&#39; \<br>    http://knlistener.default.svc</pre><h3>Java Based Event Sender</h3><p>Let’s write our own Kn event source in Java.</p><p>We need three things a sender, sink binding and a cronjob. We will keep the existing knlistener we wrote above to receive the events.</p><p><strong>Simple Java Sender</strong></p><pre>@Slf4j<br>@RestController<br>@SpringBootApplication<br>public class KnEventSender {<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(KnEventSender.class, args);<br>    }<br><br>    @Value(&quot;${ksink}&quot;)<br>    private String sink;<br><br>    @PostConstruct<br>    public void fire() {<br>        try {<br>            log.info(&quot;Fire {} &quot;, send());<br>            System.exit(0);<br>        }<br>        catch (Exception e ) {<br>            log.error(&quot;sink {}&quot;, sink);<br>            log.error(&quot;error &quot;, e);<br>        }<br>    }<br><br>    @GetMapping(value = &quot;/&quot;, produces = {MediaType.APPLICATION_JSON_VALUE})<br>    public ResponseEntity&lt;String&gt; send() {<br>        log.info(&quot;Sink {}&quot;, sink);<br>        RestTemplate restTemplate = new RestTemplate();<br>        HttpHeaders headers = new HttpHeaders();<br>        headers.setContentType(MediaType.APPLICATION_JSON);<br><br>        HttpEntity&lt;String&gt; request = new HttpEntity&lt;&gt;(&quot;{ &#39;test&#39;: &#39;from kn sender &quot; + Math.random() + &quot;&#39;}&quot;, headers);<br><br>        return restTemplate.postForEntity(sink, request, String.class);<br>    }<br><br>}</pre><p>application.yml (note the K_SINK environment variable)</p><pre>spring.application.name: kneventsender <br>ksink: ${K_SINK}</pre><p>build.gradle (kn-sender)</p><pre>mainClassName  = &quot;uk.co.ac.vadalg.KnEventSender&quot;<br><br>dependencies {<br>    implementation &#39;org.springframework.boot:spring-boot-starter-web&#39;<br>    implementation &#39;org.springframework.boot:spring-boot-starter-actuator&#39;<br>    implementation &#39;org.junit.jupiter:junit-jupiter:5.4.2&#39;<br>    testImplementation(&#39;org.springframework.boot:spring-boot-starter-test&#39;) {<br>        exclude group: &#39;org.junit.vintage&#39;, module: &#39;junit-vintage-engine&#39;<br>    }<br>}<br><br>test {<br>    useJUnitPlatform()<br>}<br><br>bootBuildImage {<br>    imageName = &#39;localhost:5007/kn-sender&#39;<br>}</pre><p><strong>Build and push to local docker registry</strong></p><blockquote><em>gradle bootBuildImage</em></blockquote><blockquote><em>docker push localhost:5007/kn-sender</em></blockquote><p>No need to create a sender service as we will use a cronjob to do that and fire events periodically.</p><p><strong>Sink Binding</strong></p><p>This references the cronjob (knsender-cron) and binds the service created by it to our kn listener.</p><pre>apiVersion: sources.knative.dev/v1alpha1<br>kind: SinkBinding<br>metadata:<br>  name: knsender-heartbeat<br>spec:<br>  subject:<br>    apiVersion: batch/v1<br>    kind: Job<br>    selector:<br>      matchLabels:<br>        app: knsender-cron<br><br>  sink:<br>    ref:<br>      apiVersion: serving.knative.dev/v1<br>      kind: Service<br>      name: knlistener<br>  ceOverrides:<br>    extensions:<br>      sink: bound</pre><blockquote><em>kubectl apply -f &lt;above&gt;</em></blockquote><p><strong>CronJob Trigger</strong></p><p>This will set up a cron job to run every minute or so and kick off our java sender in concert with the sink bind above.</p><pre>apiVersion: batch/v1beta1<br>kind: CronJob<br>metadata:<br>  name: knsender-cron<br>spec:<br>  # Run every minute<br>  schedule: &quot;* * * * *&quot;<br>  jobTemplate:<br>    metadata:<br>      labels:<br>        app: knsender-cron<br>    spec:<br>      template:<br>        spec:<br>          restartPolicy: Never<br>          containers:<br>            - name: knsender-heartbeat<br>              image: localhost:5007/kn-sender</pre><blockquote><em>kubectl apply -f &lt;above&gt;</em></blockquote><p><strong>Check out Jobs</strong></p><blockquote><em>kubectl get cronjob<br>NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE<br>knsender-cron * * * * * False 0 28s 30m</em></blockquote><blockquote><em>kubectl get job<br>NAME COMPLETIONS DURATION AGE<br>knsender-cron-1597849380 1/1 4s 3m2s<br>knsender-cron-1597849440 1/1 4s 2m2s<br>knsender-cron-1597849500 1/1 9s 62s<br>knsender-cron-1597849560 0/1 2s 2s</em></blockquote><p><strong>Listener</strong></p><p>The listener should be getting invoked and receiving events:</p><blockquote><em>kubectl logs -l serving.knative.dev/service=knlistener -c user-container — since=10m</em></blockquote><blockquote><em>2020–08–19 15:00:07.106 INFO 1 — — [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1064 ms<br>2020–08–19 15:00:07.432 INFO 1 — — [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘applicationTaskExecutor’<br>2020–08–19 15:00:07.632 INFO 1 — — [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path ‘/actuator’<br>2020–08–19 15:00:07.700 INFO 1 — — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ‘’<br>2020–08–19 15:00:07.733 INFO 1 — — [ main] uk.co.ac.vadalg.KnEventListener : Started KnEventListener in 2.14 seconds (JVM running for 2.508)<br>2020–08–19 15:00:07.753 INFO 1 — — [nio-8080-exec-3] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ‘dispatcherServlet’<br>2020–08–19 15:00:07.753 INFO 1 — — [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’<br>2020–08–19 15:00:07.758 INFO 1 — — [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Completed initialization in 5 ms<br>2020–08–19 15:00:07.834 INFO 1 — — [nio-8080-exec-3] </em><strong><em>uk.co.ac.vadalg.KnEventListener : 2020–08–19T15:00:07.834, { ‘test’: ‘from kn sender 0.9763648332730366’}</em></strong><em><br>2020–08–19 15:01:03.744 INFO 1 — — [nio-8080-exec-9] </em><strong><em>uk.co.ac.vadalg.KnEventListener : 2020–08–19T15:01:03.744, { ‘test’: ‘from kn sender 0.8349076066212481’}</em></strong></blockquote><p>There you are, java sender and listener via knative.</p><p><strong>Delete</strong></p><blockquote><em>kubectl delete cronjob knsender-cron<br>cronjob.batch “knsender-cron” deleted</em></blockquote><blockquote><em>kubectl get po<br>NAME READY STATUS RESTARTS AGE<br>knlistener-rzcpv-1-deployment-789df7845b-bgrmn 2/2 Terminating 0 4m3s</em></blockquote><h3>Conclusion</h3><p>We installed our knative event dependencies, tested the installation using standard event resources then created our own Java listener and Java sender to receive and send json based events in a ‘serverless’ manner (the pods are removed after inactivity of 30 secs).</p><h3>Event Sources</h3><p>Knative comes ready with core sources of events such as:</p><ul><li>ApiServerSource, fired when a k8s resource is created</li><li>PingSource (cronjob)</li><li>ContainerSource, container images as sources</li><li>KafkaSource</li></ul><p>See <a href="https://knative.dev/docs/eventing/sources/">https://knative.dev/docs/eventing/sources/</a></p><h3>Source Code</h3><p>All source code can be found here:</p><p><a href="https://gitlab.com/lightphos/spring/vadalg">https://gitlab.com/lightphos/spring/vadalg</a></p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/knative-build-kubernetes-docker-desktop/"><em>https://blog.ramjee.uk</em></a><em> on August 19, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7e83766297b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/simple-knative-eventing-in-kubernetes-with-a-java-listener-and-sender-d7e83766297b">Simple Knative Eventing in Kubernetes with a Java Listener and Sender</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto Pi Backup to NAS]]></title>
            <link>https://medium.com/actual-tech/auto-pi-backup-to-nas-922443c1a71?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/922443c1a71</guid>
            <category><![CDATA[onap]]></category>
            <category><![CDATA[nas]]></category>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Wed, 12 Aug 2020 10:55:48 GMT</pubDate>
            <atom:updated>2020-08-12T11:00:33.456Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/293/0*SSz3RM1wCdvp6itP.jpeg" /></figure><p>How to backup your PI as an image to a NAS.</p><h3>Set up CIFS Mount</h3><p><strong>Mount CIFS (common internet file system)</strong></p><p>sudo mount -t cifs //192.168.0.181/PIBackup /media/sd/backup/ -o user=user</p><p><strong>Mount on Boot</strong></p><p>Using fstab is a bit risky, instead add a script in say root eg:</p><p>mountNAS.sh:</p><p>add the mount command with password={pwd}</p><pre>sleep 30 <br># time for network to come up <br>mount -t cifs //192.168.0.181/PIBackup /media/sd/backup/ -o user=user,password=pwd</pre><p>then crontab -e and @reboot /root/mountNAS.sh</p><blockquote><em>chmod +x mountNAS.sh</em></blockquote><blockquote><em>crontab -e<br>@reboot /root/mountNAS.sh</em></blockquote><h3>Backup</h3><p><strong>Framps tools</strong></p><p>Using the following:</p><p><a href="https://www.linux-tips-and-tricks.de/en/raspberry/303-pi-creates-automatic-backups-of-itself/">https://www.linux-tips-and-tricks.de/en/raspberry/303-pi-creates-automatic-backups-of-itself/</a></p><p>Once downloaded run</p><p><a href="https://blog.ramjee.uk/pi-backup-to-nas/raspiBackupInstallerUI.sh">raspiBackupInstallerUI.sh</a></p><p>Chose dd/windows rather than rsync.</p><p>See: <a href="https://www.linux-tips-and-tricks.de/en/quickstart-rbk/">https://www.linux-tips-and-tricks.de/en/quickstart-rbk/</a></p><p>Cron is here:</p><p>/etc/cron.d/raspiBackup</p><pre># <br># Crontab entry for raspiBackup.sh <br># <br># (C) 2017-2019 framp at linux-tips-and-tricks dot de <br># <br># Create a backup once a week on Sunday morning at 5 am (default) <br># <br>00 03 * * 0 root /usr/local/bin/raspiBackup.sh</pre><p>The above does a weekly backup on Sunday at 3.00 am.</p><p>Manually test:</p><p>nohup /usr/local/bin/raspiBackup.sh &amp;</p><h3>Restore</h3><p>For DD backups the Windows32DiskImager can be used to restore the backup. A backup can also be restored with Raspberry Pi.</p><p>TAR or RSYNC backups have to be restored with Raspberry Pi.</p><p>For mac you can use the following to restore the image to SD card:</p><p><a href="https://www.balena.io/etcher/">https://www.balena.io/etcher/</a></p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/pi-backup-to-nas/"><em>https://blog.ramjee.uk</em></a><em> on August 12, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=922443c1a71" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/auto-pi-backup-to-nas-922443c1a71">Auto Pi Backup to NAS</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Knative Service K8s and Spring Java]]></title>
            <link>https://medium.com/actual-tech/knative-service-k8s-and-spring-java-538e269eee5f?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/538e269eee5f</guid>
            <category><![CDATA[knative]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Mon, 03 Aug 2020 11:59:30 GMT</pubDate>
            <atom:updated>2020-09-09T10:19:25.244Z</atom:updated>
            <content:encoded><![CDATA[<h4>PROGRAMMING</h4><h3>Knative Service with Kubernetes and Spring Boot</h3><h4>Install a knative service on top of kubernetes and deploy a serverless spring boot image</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*eIXSe72QWWzPHUgT.png" /></figure><h3>What is Knative</h3><p>Quote</p><blockquote><strong>Knative</strong><em> provides an open API and runtime environment that enables you to run your serverless workloads anywhere you choose: fully managed on Google Cloud, or on Anthos on Google Kubernetes Engine (GKE), or on your own Kubernetes cluster</em></blockquote><blockquote>From <a href="https://cloud.google.com/knative">https://cloud.google.com/knative</a></blockquote><h3>What is Serverless</h3><p>The purest idea behind serverless is that you write the code then something takes this code, builds and deploys and runs it without you worrying about how or where. <br>Another idea is that no resources are used until requested. You only open the tap when you need to drink. So you pay as and when you use the resources. Resources scale up or down based on demand, referred to as elastic resource utilisation.</p><p>For more on serverless see:<br><a href="https://en.wikipedia.org/wiki/Serverless_computing">https://en.wikipedia.org/wiki/Serverless_computing</a></p><h3>Knative</h3><p>We look at Knative which attempts to fulfil some of the above by creating a pod only when there is a request (although this too is configurable).</p><p>We will run up a Knative server on our local K8s cluster and deploy an existing image as a Knative service.</p><h3>Set Up</h3><p>MacOs<br>Desktop for docker: v 2.3.0.3<br>k8s: v 1.16.5</p><h3>Install Knative Serving</h3><p>Knative depends on Istio which we installed <a href="https://medium.com/@lightphos/istio-with-kubernetes-b898be1014d7">previously.</a></p><blockquote><em>kubectl apply --filename </em><a href="https://github.com/knative/serving/releases/download/v0.16.0/serving-crds.yaml"><em>https://github.com/knative/serving/releases/download/v0.16.0/serving-crds.yaml</em></a></blockquote><blockquote><em>kubectl apply --filename </em><a href="https://github.com/knative/serving/releases/download/v0.16.0/serving-core.yaml"><em>https://github.com/knative/serving/releases/download/v0.16.0/serving-core.yaml</em></a></blockquote><blockquote><em>kubectl label namespace knative-serving istio-injection=enabled</em></blockquote><p>Add knative istio connection</p><blockquote><em>kubectl apply --filename </em><a href="https://github.com/knative/net-istio/releases/download/v0.16.0/release.yaml"><em>https://github.com/knative/net-istio/releases/download/v0.16.0/release.yaml</em></a></blockquote><blockquote><em>kubectl --namespace istio-system get service istio-ingressgateway</em></blockquote><h3>Kn CLI</h3><p>Follow the link below to install:</p><p><a href="https://knative.dev/docs/install/install-kn/">https://knative.dev/docs/install/install-kn/</a></p><p>Create a test Knative service with the Knative CLI kn</p><blockquote><em>kn service create helloworld-go — image gcr.io/knative-samples/helloworld-go — env TARGET=”Go Sample v1&quot;</em></blockquote><blockquote><em>kn service describe helloworld-go<br>Name: helloworld-go<br>Namespace: default<br>Age: 4m<br>URL: </em><a href="http://helloworld-go.default.example.com/"><em>http://helloworld-go.default.example.com</em></a><em><br>Revisions: <br>100% @latest (helloworld-go-yljzr-1) [1] (4m)<br> Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)<br>Conditions: <br>OK TYPE AGE REASON<br>++ Ready 3m <br>++ ConfigurationsReady 3m <br>++ RoutesReady 3m</em></blockquote><p>Run it up, there are no pods if no requests are present, so the first request will be slow.</p><blockquote><em>curl -H “Host: helloworld-go.default.example.com” </em><a href="http://localhost/"><em>http://localhost:80</em></a><em><br>Hello Go Sample v1!</em></blockquote><p>The required pods were created on demand. If no requests are present after a certain time (default 30 secs), the pods will be removed. Nice, you only use the resource when needed provided you are ok with the initial latency.</p><p>Remove the test service.</p><blockquote><em>kn service delete helloworld-go</em></blockquote><h3>Deploy our Local image</h3><p>We have an existing local docker image, vadal-echo, we built <a href="https://medium.com/@lightphos/kong-api-gateway-with-kubernetes-a1dab930a5ba">previously</a>.</p><p>Unlike our previous blogs where we can deploy our local docker images directly to K8s, with Knative a docker registry is necessary.</p><p>The first attempt was to re-tag the local image as suggested by the documentation, and update the knative config to enable local images (see below).</p><p>Retag like so:</p><blockquote><em>docker tag vadal-echo:0.0.1-SNAPSHOT dev.local/vadal-echo</em></blockquote><p>But it still gave a failure:</p><blockquote><em>`..failed with message: Back-off pulling image “dev.local/vadal-echo`</em></blockquote><p>So plan B. Add a local registry, and push to it, plus add it to the config (see below):</p><blockquote><em>docker run -d -p 5007:5000 --name registry --restart=always registry:2</em></blockquote><p>The port 5007 is arbitrary.</p><p>Edit Knative Config:</p><blockquote><em>kubectl -n knative-serving edit configmap config-deployment</em></blockquote><p>Add the following after the data line:</p><blockquote><em>data:<br> registriesSkippingTagResolving: ko.local,dev.local,</em><strong><em>localhost:5007</em></strong></blockquote><p>Now tag and push:</p><blockquote><em>docker tag vadal-echo:0.0.1-SNAPSHOT localhost:5007/vadal-echo</em></blockquote><blockquote><em>docker push localhost:5007/vadal-echo</em></blockquote><p>Check our docker registry:</p><blockquote><em>curl localhost:5007/v2/_catalog<br>{“repositories”:[“vadal-echo”]}</em></blockquote><p>Deploy with Kn:</p><blockquote><em>kn service create vecho --image localhost:5007/vadal-echo<br>Creating service ‘vecho’ in namespace ‘default’:</em></blockquote><blockquote><em>0.053s The Configuration is still working to reflect the latest desired specification.<br>0.176s The Route is still working to reflect the latest desired specification.<br>0.227s Configuration “vecho” is waiting for a Revision to become ready.<br>12.893s …<br>13.330s Ingress has not yet been reconciled.<br>13.456s Waiting for load balancer to be ready<br>13.750s Ready to serve.</em></blockquote><blockquote><em>Service ‘vecho’ created to latest revision ‘vecho-jvjfg-1’ is available at URL:<br></em><a href="http://vecho.default.example.com/"><em>http://vecho.default.example.com</em></a></blockquote><p>Test it out:</p><blockquote><em>curl -i -H “Host: vecho.default.example.com” localhost:80<br>HTTP/1.1 200 OK<br>content-type: application/json<br>date: Tue, 21 Jul 2020 01:15:22 GMT<br>server: istio-envoy<br>x-envoy-upstream-service-time: 16<br>transfer-encoding: chunked</em></blockquote><blockquote><em>{“timestamp”:”2020–07–21T01:15:22.624&quot;,”headers”:{“host”:”vecho.default.example.com”,”user-agent”:”curl/7.64.1&quot;,”accept”:”</em>/<em>”,”accept-encoding”:”gzip”,”forwarded”:”for=192.168.65.3;proto=http, for=10.1.0.35&quot;,”k-proxy-request”:”activator”,”x-b3-parentspanid”:”884680e6f10832a3&quot;,”x-b3-sampled”:”1&quot;,”x-b3-spanid”:”f74293af107c73eb”,”x-b3-traceid”:”62d4adff218c6fe6884680e6f10832a3&quot;,”x-request-id”:”0ce4f3b5-ea69–9bd4–87bf-3aef0dfa52e1&quot;,”x-forwarded-proto”:”http”}}</em></blockquote><p>Nice, API domain name, load balancing, services and deployment configuration all done in one line. You can see the pod being created and then removed after the timeout.</p><p>List Kn services:</p><blockquote><em>kn service list<br>NAME URL LATEST AGE CONDITIONS READY REASON<br>vecho </em><a href="http://vecho.default.example.com/"><em>http://vecho.default.example.com</em></a><em> vecho-jvjfg-1 7m9s 3 OK / 3 True</em></blockquote><p>Remove the Knative service:</p><blockquote><em>kn service delete vecho</em></blockquote><p>Brute force remove if things get in a muddle:</p><blockquote><em>kubectl proxy</em></blockquote><p>then</p><blockquote><em>curl -X DELETE </em><a href="http://localhost:8001/apis/serving.knative.dev/v1alpha1/namespaces/default/services/vecho;2D"><em>http://localhost:8001/apis/serving.knative.dev/v1alpha1/namespaces/default/services/vecho</em></a></blockquote><p>The default service timeout is 30 second after which it is removed until the next request.</p><p>The pod eviction time, number of replicas etc, is the subject of autoscaling and is discussed here <a href="https://knative.dev/v0.15-docs/serving/configuring-autoscaling/">https://knative.dev/v0.15-docs/serving/configuring-autoscaling/</a>.</p><p>When there are no pods, where are the logs? For this we need to add logging.</p><h3>Observability</h3><p>Here we cover logging, tracing and metrics for the knative layer in our k8s cluster.</p><h3>Logging</h3><p>Based on the following:</p><p><a href="https://knative.dev/docs/serving/installing-logging-metrics-traces/">https://knative.dev/docs/serving/installing-logging-metrics-traces/</a></p><blockquote><em>kubectl label nodes --all beta.kubernetes.io/fluentd-ds-ready=”true”</em></blockquote><blockquote><em>kubectl apply --filename </em><a href="https://github.com/knative/serving/releases/download/v0.16.0/monitoring-core.yaml"><em>https://github.com/knative/serving/releases/download/v0.16.0/monitoring-core.yaml</em></a></blockquote><p>Knative server config changes:</p><blockquote><em>kubectl edit cm -n knative-serving config-observability</em></blockquote><p>And add the following if you also need request/access logs:</p><blockquote><em>data:<br> metrics.request-metrics-backend-destination: prometheus<br> logging.request-log-template: ‘{“httpRequest”: {“requestMethod”: “{{.Request.Method}}”, “requestUrl”: “{{js .Request.RequestURI}}”, “requestSize”: “{{.Request.ContentLength}}”, “status”: {{.Response.Code}}, “responseSize”: “{{.Response.Size}}”, “userAgent”: “{{js .Request.UserAgent}}”, “remoteIp”: “{{js .Request.RemoteAddr}}”, “serverIp”: “{{.Revision.PodIP}}”, “referer”: “{{js .Request.Referer}}”, “latency”: “{{.Response.Latency}}s”, “protocol”: “{{.Request.Proto}}”}, “traceId”: “{{index .Request.Header “X-B3-Traceid”}}”}’</em></blockquote><p>Logs:</p><blockquote><em>kubectl apply --filename </em><a href="https://github.com/knative/serving/releases/download/v0.16.0/monitoring-logs-elasticsearch.yaml"><em>https://github.com/knative/serving/releases/download/v0.16.0/monitoring-logs-elasticsearch.yaml</em></a></blockquote><p>Make sure all is well (desktop for docker may need the number of CPUs used to be increased if any pods are stuck in pending).</p><blockquote><em>kubectl get po -n knative-monitoring</em></blockquote><blockquote><em>NAME READY STATUS RESTARTS AGE<br>elasticsearch-logging-0 1/1 Running 0 34m<br>elasticsearch-logging-1 1/1 Running 0 32m<br>fluentd-ds-l6mgg 1/1 Running 0 105s<br>kibana-logging-669968b8d4-nc4b2 1/1 Running 0 34m</em></blockquote><p>Check out the Kibana UI:</p><p><a href="http://localhost:8001/api/v1/namespaces/knative-monitoring/services/kibana-logging/proxy/app/kibana">http://localhost:8001/api/v1/namespaces/knative-monitoring/services/kibana-logging/proxy/app/kibana</a></p><p>Setting as below and create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FQPqNYmEmr0TJwpt.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eWvugJvK71MQ6JoH.png" /></figure><h3>Tracing</h3><p><a href="http://localhost:8001/api/v1/namespaces/istio-system/services/zipkin:9411/proxy/zipkin/">http://localhost:8001/api/v1/namespaces/istio-system/services/zipkin:9411/proxy/zipkin/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y20veVuaCamUoPjr.png" /></figure><blockquote><em>kubectl apply --filename </em><a href="https://github.com/knative/serving/releases/download/v0.16.0/monitoring-tracing-zipkin.yaml"><em>https://github.com/knative/serving/releases/download/v0.16.0/monitoring-tracing-zipkin.yaml</em></a></blockquote><h3>Metrics</h3><blockquote><em>kubectl apply --filename </em><a href="https://github.com/knative/serving/releases/download/v0.16.0/monitoring-metrics-prometheus.yaml"><em>https://github.com/knative/serving/releases/download/v0.16.0/monitoring-metrics-prometheus.yaml</em></a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XDINJ_5Ml3nOAZwC.png" /></figure><blockquote><em>kubectl port-forward --namespace knative-monitoring <br>$(kubectl get pods --namespace knative-monitoring <br> --selector=app=grafana --output=jsonpath=”{.items..metadata.name}”) <br>3000</em></blockquote><h3>Conclusion</h3><p>We installed the Knative Serving component, added a local docker registry and deployed an existing service with Kn. As pods are ephemeral, Istio logs are of no use, but we can use Kibana to look at the logs. We also added tracing and metrics.</p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/knative-serving/"><em>https://blog.ramjee.uk</em></a><em> on August 3, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=538e269eee5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/knative-service-k8s-and-spring-java-538e269eee5f">Knative Service K8s and Spring Java</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka in Kubernetes with Spring]]></title>
            <link>https://medium.com/actual-tech/kafka-in-kubernetes-with-spring-c51961635668?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c51961635668</guid>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Fri, 24 Jul 2020 00:10:03 GMT</pubDate>
            <atom:updated>2020-09-07T10:32:44.026Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*OezlyAMgl93ULMJr.png" /></figure><p>We install Kafka in Kubernetes (k8s) with Istio Service Mesh and a Spring boot application to send and receive messages with Kafka.</p><p><strong>What does Kafka give you?</strong><br>Speed. High Volume, across commodity hardware. Guaranteed ordering. Message Replay. Horizontal (Distributed) Scaling. Replication for resilience.</p><p><strong>Where to use it?</strong><br>Event driven applications. Event sourcing with event logs. Metrics. Real time stream processing. Used in areas where RabbitMQ and AMQP are unable to handle the volume and speed needed.</p><p><strong>Our Setup</strong><br>Docker desktop in macos, with its in built k8s. Set the resources to at least 6G, and cores to 2+.</p><h3>Installing Kafka on K8s</h3><p>This is based on <a href="https://strimzi.io/quickstarts/">https://strimzi.io/quickstarts/</a></p><p>If you have followed my <a href="https://medium.com/@lightphos/istio-with-kubernetes-b898be1014d7">previous</a> posts with Istio the following namespace should already have been created.</p><blockquote><em>kubectl create namespace vadal</em></blockquote><p>and this namespace has already been assigned to Istio for sidecar injection.</p><blockquote><em>kubectl label namespace vadal istio-injection=enabled</em></blockquote><h3>Kafka Setup</h3><p>Add required CRDs</p><blockquote><em>kubectl apply -f ‘https://strimzi.io/install/latest?namespace=vadal&#39; -n vadal</em></blockquote><p>Create the persistent kafka cluster</p><blockquote><em>kubectl apply -f </em><a href="https://strimzi.io/examples/latest/kafka/kafka-persistent-single.yaml"><em>https://strimzi.io/examples/latest/kafka/kafka-persistent-single.yaml</em></a><em> -n vadal</em></blockquote><p>Wait for it.</p><blockquote><em>kubectl wait kafka/my-cluster — for=condition=Ready — timeout=300s -n vadal</em></blockquote><p>Check the pods</p><blockquote><em>kc get pods -n vadal | grep cluster<br>my-cluster-entity-operator-6b7d7657dd-2pv6s 4/4 Running 1 76s<br>my-cluster-kafka-0 3/3 Running 0 99s<br>my-cluster-zookeeper-0 2/2 Running 0 2m10s<br>strimzi-cluster-operator-6c9d899778-ql9nn 2/2 Running 0 4m49s</em></blockquote><h3>Check Connectivity</h3><p><strong>Send</strong></p><blockquote><em>kubectl -n vadal run kafka-producer -ti --image=strimzi/kafka:0.18.0-kafka-2.5.0 --rm=true --restart=Never --bin/kafka-console-producer.sh --broker-list my-cluster-kafka-bootstrap:9092 --topic my-topic</em></blockquote><blockquote><em>If you don’t see a command prompt, try pressing enter.</em></blockquote><blockquote><strong><em>hi there</em></strong><em><br>&gt;</em></blockquote><p><strong>Receive</strong></p><blockquote><em>kubectl -n vadal run kafka-consumer -ti --image=strimzi/kafka:0.18.0-kafka-2.5.0 --rm=true --restart=Never --bin/kafka-console-consumer.sh --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic my-topic --from-beginning<br> {my-topic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)</em></blockquote><blockquote><strong><em>hi there</em></strong></blockquote><h3>View in Kiali</h3><p>This will only work if you have Istio installed with all the goodies. Also you will need to have followed the example using a namespace labelled with istio injection (see above).</p><blockquote>istioctl dashboard kiali</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aT133Eh0jRvHZZ9F.png" /></figure><p>A lot going on here as you can see. There are the bootstrap, broker and zookeeper pods at play.</p><h3>Spring Kafka</h3><p>Application</p><pre>@SpringBootApplication<br>@RestController<br>@Slf4j<br>public class VadalApplication {<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(VadalApplication.class, args);<br>    }<br><br>    private static final String TOPIC = &quot;my-topic&quot;;<br><br>    private final List&lt;String&gt; CONSUMED_MESSAGES = new ArrayList&lt;&gt;();<br><br>    @Autowired<br>    private KafkaTemplate&lt;String, String&gt; kafkaTemplate;<br><br>    @KafkaListener(topics = TOPIC, groupId = &quot;group_id&quot;)<br>    public void consume(String m) {<br>        log.info(&quot;Message consumed: {}&quot;, m);<br>        CONSUMED_MESSAGES.add(m);<br>    }<br><br>    @GetMapping(&quot;/pub/{m}&quot;)<br>    public void produce(@PathVariable String m) {<br>        log.info(&quot;Message produced: {}&quot;, m);<br>        kafkaTemplate.send(TOPIC, m);<br>    }<br><br>    @GetMapping(&quot;/get&quot;)<br>    public List&lt;String&gt; get() {<br>        log.info(&quot;Get consumed messages&quot;);<br>        List&lt;String&gt; l = new ArrayList&lt;&gt;(CONSUMED_MESSAGES);<br>        CONSUMED_MESSAGES.clear();<br>        return l;<br>    }<br><br>}</pre><p>The Spring Kafka wiring will create the topic if it does not exist (no need for the NewTopic method although you can add it).</p><p>The /pub endpoint publishes the message string, the KafkaListener receives the messages and stores them in a list. The /get endpoint retrieves from this list. This is obviously a contrived example to demonstrate Kafka interaction with Java Spring.</p><p><em>If you have multiple instances, then to save the message, you would need a common store such as a Db or a DataGrid.</em></p><p>POM</p><pre>    &lt;dependencies&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring-kafka&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;io.micrometer&lt;/groupId&gt;<br>            &lt;artifactId&gt;micrometer-registry-prometheus&lt;/artifactId&gt;<br>            &lt;scope&gt;runtime&lt;/scope&gt;<br>        &lt;/dependency&gt;<br>    &lt;/dependencies&gt;</pre><p>I’ve left in spring-boot-starter-data-rest from previous applications, it can be replaced by spring-boot-starter-web if you wish. The parent pom has the main spring, lombok etc dependencies (see the full code <a href="https://gitlab.com/lightphos/spring/vadal">here</a>).</p><p>application.yml</p><pre>server.port: 7777<br><br>spring:<br>  kafka:<br>    consumer:<br>      bootstrap-servers: my-cluster-kafka-bootstrap:9092<br>      group-id: group_id<br>      auto-offset-reset: earliest<br>      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer<br>      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer<br>    producer:<br>      bootstrap-servers: my-cluster-kafka-bootstrap:9092<br>      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer<br>      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer<br><br><br>management:<br>  endpoints:<br>    web:<br>      exposure:<br>        include: &quot;*&quot;</pre><p>Note the bootstrap-servers are those we created earlier with strimzi CRDs.</p><p>Create the image:</p><blockquote>mvn spring-boot:build-image</blockquote><p>This should create a vadal-kafka-message:0.0.1-SNAPSHOT docker image.</p><h3>Deploy and Serve</h3><blockquote><em>kubectl create deployment vkafka — image vadal-kafka-message:0.0.1-SNAPSHOT -n vadal</em></blockquote><blockquote><em>kubectl expose deployment vkafka — type NodePort — port 8888 — target-port 7777 -n vadal</em></blockquote><blockquote><em>kc get svc -n vadal</em></blockquote><blockquote><em>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE<br>my-cluster-kafka-bootstrap ClusterIP 10.107.228.196 &lt;none&gt; 9091/TCP,9092/TCP,9093/TCP 38h<br>my-cluster-kafka-brokers ClusterIP None &lt;none&gt; 9091/TCP,9092/TCP,9093/TCP 38h<br>my-cluster-zookeeper-client ClusterIP 10.111.83.76 &lt;none&gt; 2181/TCP 38h<br>my-cluster-zookeeper-nodes ClusterIP None &lt;none&gt; 2181/TCP,2888/TCP,3888/TCP 38h<br>vkafka NodePort 10.102.114.125 &lt;none&gt; 8888:32758/TCP 37h</em></blockquote><p><strong>Send a message through our application</strong></p><blockquote><em>curl -i localhost:32758/pub/test-message<br>HTTP/1.1 200 OK<br>content-length: 0<br>date: Mon, 20 Jul 2020 13:32:56 GMT<br>x-envoy-upstream-service-time: 122<br>server: istio-envoy<br>x-envoy-decorator-operation: vkafka.vadal.svc.cluster.local:8888/*</em></blockquote><p><strong>Check the logs</strong></p><blockquote><em>kc get po -n vadal<br>NAME READY STATUS RESTARTS AGE<br>vkafka-546f454db9-kpkv9 2/2 Running 1 36h</em></blockquote><blockquote><em>kc logs vkafka-546f454db9-kpkv9 -n vadal vadal-kafka-message</em></blockquote><pre>2020-07-20 13:32:57.153  INFO 1 --- [nio-7777-exec-2] u.c.a.vadalkafka.VadalApplication        : Message produced: test-message<br>2020-07-20 13:32:57.162  INFO 1 --- [nio-7777-exec-2] o.a.k.clients.producer.ProducerConfig    : ProducerConfig values: <br>	acks = 1<br>	batch.size = 16384<br>	bootstrap.servers = [my-cluster-kafka-bootstrap:9092]<br>	buffer.memory = 33554432<br>	client.dns.lookup = default<br>	client.id = producer-1<br>	compression.type = none<br>	connections.max.idle.ms = 540000<br>	delivery.timeout.ms = 120000<br>	enable.idempotence = false<br>	interceptor.classes = []<br>	key.serializer = class org.apache.kafka.common.serialization.StringSerializer<br>	linger.ms = 0<br>	max.block.ms = 60000<br>	max.in.flight.requests.per.connection = 5<br>	max.request.size = 1048576<br>	metadata.max.age.ms = 300000<br>	metadata.max.idle.ms = 300000<br>	metric.reporters = []<br>	metrics.num.samples = 2<br>	metrics.recording.level = INFO<br>	metrics.sample.window.ms = 30000<br>	partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner<br>	receive.buffer.bytes = 32768<br>	reconnect.backoff.max.ms = 1000<br>	reconnect.backoff.ms = 50<br>	request.timeout.ms = 30000<br>	retries = 2147483647<br>	retry.backoff.ms = 100<br>	sasl.client.callback.handler.class = null<br>	sasl.jaas.config = null<br>	sasl.kerberos.kinit.cmd = /usr/bin/kinit<br>	sasl.kerberos.min.time.before.relogin = 60000<br>	sasl.kerberos.service.name = null<br>	sasl.kerberos.ticket.renew.jitter = 0.05<br>	sasl.kerberos.ticket.renew.window.factor = 0.8<br>	sasl.login.callback.handler.class = null<br>	sasl.login.class = null<br>	sasl.login.refresh.buffer.seconds = 300<br>	sasl.login.refresh.min.period.seconds = 60<br>	sasl.login.refresh.window.factor = 0.8<br>	sasl.login.refresh.window.jitter = 0.05<br>	sasl.mechanism = GSSAPI<br>	security.protocol = PLAINTEXT<br>	security.providers = null<br>	send.buffer.bytes = 131072<br>	ssl.cipher.suites = null<br>	ssl.enabled.protocols = [TLSv1.2]<br>	ssl.endpoint.identification.algorithm = https<br>	ssl.key.password = null<br>	ssl.keymanager.algorithm = SunX509<br>	ssl.keystore.location = null<br>	ssl.keystore.password = null<br>	ssl.keystore.type = JKS<br>	ssl.protocol = TLSv1.2<br>	ssl.provider = null<br>	ssl.secure.random.implementation = null<br>	ssl.trustmanager.algorithm = PKIX<br>	ssl.truststore.location = null<br>	ssl.truststore.password = null<br>	ssl.truststore.type = JKS<br>	transaction.timeout.ms = 60000<br>	transactional.id = null<br>	value.serializer = class org.apache.kafka.common.serialization.StringSerializer<br><br>2020-07-20 13:32:57.186  INFO 1 --- [nio-7777-exec-2] o.a.kafka.common.utils.AppInfoParser     : Kafka version: 2.5.0<br>2020-07-20 13:32:57.186  INFO 1 --- [nio-7777-exec-2] o.a.kafka.common.utils.AppInfoParser     : Kafka commitId: 66563e712b0b9f84<br>2020-07-20 13:32:57.186  INFO 1 --- [nio-7777-exec-2] o.a.kafka.common.utils.AppInfoParser     : Kafka startTimeMs: 1595251977185<br>2020-07-20 13:32:57.201  INFO 1 --- [ad | producer-1] org.apache.kafka.clients.Metadata        : [Producer clientId=producer-1] Cluster ID: tao-huzJTTGmMCqwhtQF1Q<br>2020-07-20 13:32:57.280  INFO 1 --- [ntainer#0-0-C-1] u.c.a.vadalkafka.VadalApplication        : Message consumed: test-message</pre><p>We can see the listener consuming the message.</p><p>Lets grab it via our get endpoint</p><blockquote><em>curl -i localhost:32758/get<br>HTTP/1.1 200 OK<br>content-type: application/json<br>date: Mon, 20 Jul 2020 13:38:37 GMT<br>x-envoy-upstream-service-time: 12<br>server: istio-envoy<br>x-envoy-decorator-operation: vkafka.vadal.svc.cluster.local:8888/*<br>transfer-encoding: chunked<br></em><strong><em>[“test-message”]</em></strong></blockquote><h3>Kafka GUI</h3><p>There is a Kakfa GUI which can be deployed to K8s.</p><p>See:<br><a href="https://github.com/spring-projects/spring-kafka/tree/master/samples">https://github.com/spring-projects/spring-kafka/tree/master/samples</a></p><blockquote><em>helm repo add akhq </em><a href="https://akhq.io/"><em>https://akhq.io/</em></a></blockquote><blockquote><em>helm install --name akhq akhq/akhq --namespace vadal</em></blockquote><p>Edit akhq-secrets to change the bootstrap.serversfrom <strong>kafka</strong>:9092 to <strong>my-cluster-kafka-bootstrap</strong>:9092 (you can do it by hand or use Lens <a href="https://k8slens.dev/">https://k8slens.dev/</a>)</p><p>Edit service to provide a nodeport say 30011, delete the akhq pod and let it restart, then you can navigate to it.</p><p><a href="http://localhost:30011/my-cluster-plain-text/topic">http://localhost:30011/my-cluster-plain-text/topic</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Hgk-8sdoaqnGvbI.png" /></figure><h3>Conclusion</h3><p>There we go, Kakfa running in K8s, a spring boot application which reads and writes to it and a GUI to boot.</p><h3>Further Reading</h3><p><a href="https://strimzi.io/docs/operators/latest/overview.html#configuration-points-connect_str">https://strimzi.io/docs/operators/latest/overview.html#configuration-points-connect_str</a></p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/kafka-in-kubernetes-with-spring/"><em>https://blog.ramjee.uk</em></a><em> on July 24, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c51961635668" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/kafka-in-kubernetes-with-spring-c51961635668">Kafka in Kubernetes with Spring</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hazelcast Kubernetes Istio Kiali and Spring Data]]></title>
            <link>https://medium.com/actual-tech/hazelcast-kubernetes-istio-kiali-and-spring-data-f99022f0db77?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f99022f0db77</guid>
            <category><![CDATA[hazelcast]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Thu, 23 Jul 2020 23:05:47 GMT</pubDate>
            <atom:updated>2020-07-23T23:20:13.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*H_H7autw1dZs40UU.png" /></figure><blockquote><em>Quote:</em></blockquote><blockquote><strong><em>Hazelcast</em></strong><em> provides central, predictable scaling of applications through in-memory access to frequently </em><strong><em>used</em></strong><em> data and across an elastically scalable data grid. These techniques reduce the query load on databases and improve speed. .<br></em><a href="https://en.wikipedia.org/wiki/Hazelcast#:~:text=Hazelcast%20provides%20central%2C%20predictable%20scaling,on%20databases%20and%20improve%20speed.&amp;text=The%20Hazelcast%20platform%20can%20manage%20memory%20for%20many%20different%20types%20of%20applications."><em>https://en.wikipedia.org/wiki/Hazelcast#:~:text=Hazelcast%20provides%20central%2C%20predictable%20scaling,on%20databases%20and%20improve%20speed.&amp;text=The%20Hazelcast%20platform%20can%20manage%20memory%20for%20many%20different%20types%20of%20applications.</em></a></blockquote><p>We deploy a hazelcast enabled java service that shares a data object in the memory grid between its instances. The data object is just like a normal database repository and we use the hazelcast spring data extension to read and write it. This is an interesting use case from the usual distributed caching ability hazelcast is used for. You can view and insert objects with the normal spring data methods, very useful.</p><p>We also deploy this within K8s and Istio giving us the load balancing and observability capabilities (with Kiali). Previous posts detail how this is done. We use our normal setup of macos running desktop for docker with kubernetes. This exercise can equally be done using minikube or kind.</p><h3>Spring Data Application Code</h3><p>Spring boot application code:</p><pre>@SpringBootApplication<br>@RestController<br>@EnableHazelcastRepositories<br>@Slf4j<br>public class VadalUsersHCApplication {<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(VadalUsersHCApplication.class, args);<br>    }<br><br>    @Autowired<br>    UserRepo userRepo;<br><br>    @PostConstruct<br>    public void init() {<br>        List&lt;User&gt; users = Arrays.asList(new User(&quot;fred&quot;, &quot;boss&quot;), new User(&quot;wilma&quot;, &quot;director&quot;));<br>        users.forEach(user -&gt; {<br>            List&lt;User&gt; result = userRepo.findByName(user.getName());<br>            if (result.isEmpty()) {<br>                userRepo.save(user);<br>            }<br>        });<br>    }<br><br>    @Bean<br>    Config config() {<br>        Config config = new Config();<br>        JoinConfig join = config.getNetworkConfig().getJoin();<br>        join.getTcpIpConfig().setEnabled(false);<br>        join.getMulticastConfig().setEnabled(false);<br>        join.getKubernetesConfig().setEnabled(true)<br>                .setProperty(&quot;namespace&quot;, &quot;vadal&quot;)<br>                .setProperty(&quot;service-name&quot;, &quot;vhazelcast&quot;); // endpoint name in the service port<br>        return config;<br>    }<br><br>    @GetMapping(value = &quot;/users&quot;)<br>    public Iterable&lt;User&gt; getUsers(HttpServletRequest request) {<br>        log.info(LocalDateTime.now() + &quot;, &quot; + request.getRequestURL());<br>        return userRepo.findAll();<br>    }<br><br>    @PostMapping(value = &quot;/user/{name}/{handle}&quot;)<br>    public User addUser(HttpServletRequest request, @PathVariable(&quot;name&quot;) String name, @PathVariable(&quot;handle&quot;) String handle)  {<br>        User user = new User(name, handle);<br>        log.info(LocalDateTime.now() + &quot;, &quot; + request.getRequestURL() + &quot;, &quot; + user);<br>        return userRepo.save(user);<br>    }</pre><p>User class:</p><pre>@Data<br>@NoArgsConstructor<br>@ToString<br>public class User implements Serializable {<br><br>    @Id<br>    private Long id;<br>    private String name;<br>    private String handle;<br><br>    public User(String name, String handle) {<br>        this.name = name;<br>        this.handle = handle;<br>    }<br><br>}</pre><p>UserRepo class:</p><pre>public interface UserRepo extends HazelcastRepository&lt;User, Long&gt; {<br>    List&lt;User&gt; findByName(@Param(&quot;n&quot;) String name);<br>}</pre><p>The full code can be found <a href="https://gitlab.com/lightphos/spring/vadal/-/tree/master/vadal-users-hazelcast">here</a>. The shared memory grid is initialised with objects in the PostConstruct. However we check first for existing objects with the same name as we will have multiple instances.</p><p>POM Snippet (inherited, check out the full source code, for spring dependencies etc):</p><pre>&lt;properties&gt;<br>        &lt;spring.data.hazelcast.version&gt;2.2.2&lt;/spring.data.hazelcast.version&gt;<br>        &lt;kubernetes.hazelcast.version&gt;1.5.2&lt;/kubernetes.hazelcast.version&gt;<br>    &lt;/properties&gt;<br><br>    &lt;dependencies&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;com.hazelcast&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring-data-hazelcast&lt;/artifactId&gt;<br>            &lt;version&gt;${spring.data.hazelcast.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;com.hazelcast&lt;/groupId&gt;<br>            &lt;artifactId&gt;hazelcast-spring&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;com.hazelcast&lt;/groupId&gt;<br>            &lt;artifactId&gt;hazelcast-client&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;com.hazelcast&lt;/groupId&gt;<br>            &lt;artifactId&gt;hazelcast-kubernetes&lt;/artifactId&gt;<br>            &lt;version&gt;${kubernetes.hazelcast.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br><br>        &lt;dependency&gt;<br>            &lt;groupId&gt;io.micrometer&lt;/groupId&gt;<br>            &lt;artifactId&gt;micrometer-registry-prometheus&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>    &lt;/dependencies&gt;</pre><p>Build this in the usual manner.</p><blockquote><em>mvn spring-boot:build-image</em></blockquote><p>vadal-users-hazelcast:0.0.1-SNAPSHOT</p><h3>Deployment, Services, Permissions</h3><p>The application image exposes two ports, our user service and the embedded hazelcast code on port 5701. The vhazelcast port name in the first service is what our java application code in its config looks for (this config could also be placed in the application.yml file). We have set the replicas to two so we should expect two pods to be started and hazelcast linking the two. The cluster binding may or may not be needed depending on your K8s setup. It seemed to make no difference in desktop for docker K8s.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: vusershc<br>  namespace: vadal<br>  labels:<br>    app: vusershc<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: vusershc<br>  template:<br>    metadata:<br>      labels:<br>        app: vusershc<br>    spec:<br>      containers:<br>        - name: vadal-users-hazelcast<br>          image: vadal-users-hazelcast:0.0.1-SNAPSHOT<br>          ports:<br>          - containerPort: 7777<br>          - containerPort: 5701<br><br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: vhazelcast<br>  namespace: vadal<br>spec:<br>  selector:<br>    app: vusershc<br>  ports:<br>    - name: vhazelcast<br>      port: 5701<br>  type: LoadBalancer<br><br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: vusershc<br>  namespace: vadal<br>  labels:<br>    app: vusershc<br>spec:<br>  ports:<br>    - name: http<br>      port: 7777<br>      protocol: TCP<br>  selector:<br>    app: vusershc<br>  type: NodePort<br><br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRoleBinding<br>metadata:<br>  name: default-cluster<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: view<br>subjects:<br>  - kind: ServiceAccount<br>    name: default<br>    namespace: default</pre><p>kubectl apply -f — &lt;above&gt;</p><p>This should deploy and set up the services.</p><p>You can check the logs in Kiali (see previous <a href="https://medium.com/@lightphos/istio-with-kubernetes-b898be1014d7">blog</a>).</p><p>Logs from one of the workloads:</p><blockquote><em>Members {size:2, ver:2} [<br> Member [10.1.2.83]:5701 — b85b78f8–08ac-47d9–9a33-bb6315eedc90 this<br> Member [10.1.2.84]:5701–21cd8100–10aa-47be-b236–069ec90f8478<br> ]</em></blockquote><p>Two members linked to each other, from the two replicas, nice.</p><p>Find our application services NodePort:</p><blockquote><em>kc get svc -n vadal | grep hc<br>vusershc NodePort 10.111.27.233 7777:</em><strong><em>32334</em></strong><em>/TCP 25h</em></blockquote><blockquote><em>curl </em><a href="http://localhost:32334/users"><em>http://localhost:32334/users</em></a></blockquote><blockquote><em>[{“id”:-7621056571992339709,”name”:”fred”,”handle”:”boss”},{“id”:-4624569787408292316,”name”:”wilma”,”handle”:”director”}]</em></blockquote><p>That’s our IMDG acting like a database, across both instances.</p><p>Istio is also providing load balancing across the two services, which can be verified by checking the logs.</p><p>We can add a new entry:</p><blockquote><em>curl </em><a href="http://localhost:32334/user/pebbles/baby"><em>http://localhost:32334/user/pebbles/baby</em></a><em> -X POST<br>{“id”:-5517234661065649476,”name”:”pebbles”,”handle”:”baby”}</em></blockquote><p>Query:</p><blockquote><em>curl </em><a href="http://localhost:32334/users"><em>http://localhost:32334/users</em></a><em><br>[{“id”:-5517234661065649476,”name”:”pebbles”,”handle”:”baby”},{“id”:-7621056571992339709,”name”:”fred”,”handle”:”boss”},{“id”:-4624569787408292316,”name”:”wilma”,”handle”:”director”}]</em></blockquote><p>We can scale the services:</p><blockquote><em>kubectl scale deployment/vusershc -n vadal — replicas=3<br>deployment.apps/vusershc scaled</em></blockquote><p>Check out hazelcast membership in the logs:</p><p>All three pods join as members.</p><blockquote><em>Members {size:3, ver:3} [<br> Member [10.1.2.83]:5701 — b85b78f8–08ac-47d9–9a33-bb6315eedc90<br> Member [10.1.2.84]:5701–21cd8100–10aa-47be-b236–069ec90f8478 this<br> Member [10.1.2.85]:5701–8033f1d6-eb9b-408b-b97e-9b6ec2c5bc76<br>]</em></blockquote><p>And with Istio the request is distributed across the instances.</p><h3>Session Affinity</h3><p>Using this technique it would be relatively easy to construct a session class and hold session data common across all the instances. This would provide a highly scalable resilient solution with very low latency by adding a few dependencies. There is no need for complicated Nginx rules, routes, header manipulation etc. If you’ve encountered this issue with JBoss instances and Nginx servers you know how tricky this can be.</p><p>With K8s and Istio it just scales distributing the load and the sessions are common in memory between all member instances. Auto-magical.</p><p>See the links below on session replication on why this is a big deal.</p><h3>Observability</h3><p>As well as logs, Kiali provides us with useful visuals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*53ICvXUBBZkhmZDY.png" /></figure><p>You can see the hazelcast endpoint communicating with itself and you can gain details on the links.</p><h3>Kubernetes API</h3><p>The hazelcast K8s code uses K8s API to connect to the hazelcast endpoint (there is DNS way of connecting as well), and we can view that this exists in the following way.</p><blockquote><em>kc proxy</em></blockquote><p><a href="http://localhost:8001/api/v1/namespaces/vadal/endpoints/hazelcast">http://localhost:8001/api/v1/namespaces/vadal/endpoints/vhazelcast</a></p><h3>Conclusion</h3><p>We have deployed our Spring application with Hazelcast embedded to K8s with Istio acting as the service mesh. The Spring Data code acts exactly as if we were talking to a database, quite powerful this. The same data is shared across this distributed set of instances and this is done dynamically as we use K8s power to scale the number of instances.</p><p>In order to add a gateway URL or security in Istio or Kong, check out my previous <a href="https://medium.com/swlh/istio-api-security-in-kubernetes-with-jwt-a9848f228bab">blog</a>.</p><h3>Further Reading</h3><p><a href="https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-data-hazelcast-chemistry-sample">https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-data-hazelcast-chemistry-sample</a> <a href="https://hazelcast.com/blog/spring-boot-hazelcast-session-replication/">https://hazelcast.com/blog/spring-boot-hazelcast-session-replication/</a></p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/hazelcast-kubernetes-spring-boot/"><em>https://blog.ramjee.uk</em></a><em> on July 23, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f99022f0db77" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/hazelcast-kubernetes-istio-kiali-and-spring-data-f99022f0db77">Hazelcast Kubernetes Istio Kiali and Spring Data</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Observability With Istio, Kiali, and Grafana in Kubernetes and Spring Boot]]></title>
            <link>https://medium.com/swlh/observability-with-istio-kiali-and-grafana-in-kubernetes-and-spring-boot-743af225c24f?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/743af225c24f</guid>
            <category><![CDATA[kiali]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Wed, 15 Jul 2020 18:17:02 GMT</pubDate>
            <atom:updated>2020-08-02T19:30:47.532Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*U_HPs-88L1b1T-g1.png" /></figure><h3>Create REST Connected Services</h3><p>Slightly contrived example, we have two services, vadal-users and vadal-posts. Vadal-posts contains a list of posts for users identified by their user id. Vadal-posts makes a REST call to vadal-users to find the name of the user based on the user id. This allows Kiali to gather tracing and traffic details.</p><p>Add vadal-users and vadal-posts spring-boot java services. See source code here <a href="https://gitlab.com/lightphos/spring/vadal">https://gitlab.com/lightphos/spring/vadal</a>.</p><p>In essence vpost calls vuser (we have added two posts):</p><pre>@GetMapping(value = &quot;/posts&quot;)<br>    public Iterable&lt;Post&gt; getPosts(HttpServletRequest request) {<br>        log.info(LocalDateTime.now() + &quot;, &quot; + request.getRequestURL());<br>        Iterable&lt;Post&gt; posts = postRepo.findAll();<br>        posts.forEach(post -&gt; {<br>            ResponseEntity&lt;User&gt; userResponse = restTemplate.getForEntity(userService + &quot;/u/&quot; + post.getUserId(), User.class);<br>            log.info(&quot;User returned {}&quot;, userResponse.getBody().getName());<br>            post.setUser(userResponse.getBody().getName());<br>        });<br><br>        return posts;<br>    }</pre><p>In vadal-posts in the application.yml we define the following:</p><pre>spring.application.name: Vadal Posts<br>freds.id: ${FREDS.ID:3}<br>wilmas.id: ${WILMAS.ID:4}<br><br>user.service: ${USER.SERVICE:http://localhost:7777}</pre><p>As usual build the docker image using build pack.</p><blockquote><em>mvn spring-boot:build-image for both.</em></blockquote><h3>Deploy To K8s</h3><p>Help with RSI.</p><blockquote><em>alias kc=`kubectl`</em></blockquote><p>Deploy vusers.</p><blockquote><em>kc create deployment vusers — image=vadal-users:0.0.1-SNAPSHOT -n vadal</em></blockquote><blockquote><em>kc expose deployment vusers — port 80 — target-port 7777 -n vadal</em></blockquote><p>Deploy vposts (we need to provide the USER.SERVICE environment variable for vposts to call vuser). Run the following:</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: vposts<br>  namespace: vadal<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: vposts<br>  template:<br>    metadata:<br>      labels:<br>        app: vposts<br>    spec:<br>      containers:<br>        - name: vposts<br>          image: vadal-posts:0.0.1-SNAPSHOT<br>          ports:<br>            - containerPort: 8888<br>          env:<br>            - name: USER.SERVICE<br>              value: http://vusers.vadal.svc.cluster.local:80<br>EOF</pre><p>Expose the service:</p><blockquote><em>kc expose deployment vposts — type NodePort — port 8888 — target-port 8888 -n vadal</em></blockquote><p>Check the logs manually:</p><blockquote><em>kc get pods -n vadal | grep post<br>vposts-5585dfffbd-mpxkm 2/2 Running 0 3m46s</em></blockquote><blockquote><em>kc logs vposts -c vadal-posts -n vadal</em></blockquote><pre>2020-07-11T22:44:12.158095261Z Hibernate: call next value for hibernate_sequence<br>2020-07-11T22:44:12.166799807Z Hibernate: insert into post (details, topic, user, user_id, id) values (?, ?, ?, ?, ?)<br>2020-07-11T22:44:12.172370297Z Hibernate: insert into post (details, topic, user, user_id, id) values (?, ?, ?, ?, ?)<br>2020-07-11T22:44:12.174744664Z 2020-07-11 22:44:12.174  INFO 1 --- [</pre><p>USER.SERVICE has been set to <a href="http://vusers.svc.cluster.local./">http://vusers.vadal.svc.cluster.local.</a></p><p>Also you can view the logs in Kiali (see <a href="https://medium.com/@lightphos/istio-with-kubernetes-b898be1014d7">previous</a> post):</p><p><a href="http://localhost:30004/kiali/console/namespaces/vadal/workloads/vposts?tab=logs">http://localhost:30004/kiali/console/namespaces/vadal/workloads/vposts?tab=logs</a></p><p>Check out the vposts service.</p><blockquote><em>curl -i localhost:31436/posts<br>HTTP/1.1 200 OK<br>content-type: application/json<br>date: Sat, 11 Jul 2020 23:20:02 GMT<br>x-envoy-upstream-service-time: 519<br>server: istio-envoy<br>x-envoy-decorator-operation: vposts.vadal.svc.cluster.local<br>transfer-encoding: chunked</em></blockquote><pre>[ { id: 1, userId: 3, user: &quot;fred&quot;, topic: &quot;freds topic&quot;, details: &quot;rock city works&quot; }, { id: 2, userId: 4, user: &quot;wilma&quot;, topic: &quot;wilmas shop&quot;, details: &quot;stone mall&quot; } ]</pre><h3>Istio and Kiali Observation</h3><p>Create a gateway and virtual service for vposts within Istio, this will enable the inter-service communication visualisation.</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: networking.istio.io/v1alpha3<br>kind: Gateway<br>metadata:<br>  name: vadal-gateway<br>  namespace: istio-system<br>spec:<br>  selector:<br>    istio: ingressgateway # use istio default controller<br>  servers:<br>    - port:<br>        number: 80<br>        name: http<br>        protocol: http<br>      hosts:<br>        - vadal.local<br><br>---<br>apiVersion: networking.istio.io/v1alpha3<br>kind: VirtualService<br>metadata:<br>  name: posts<br>  namespace: vadal<br>spec:<br>  hosts:<br>    - vadal.local<br>  gateways:<br>    - vadal-gateway.istio-system.svc.cluster.local<br>  http:<br>    - match:<br>        - uri:<br>            exact: /posts<br>      route:<br>        - destination:<br>            host: vposts.vadal.svc.cluster.local<br>            port:<br>              number: 8888<br>EOF</pre><p>Add vadal.local to your /etc/hosts with it pointing to your hosts IP.</p><p>Check it out:</p><blockquote><em>curl -i </em><a href="http://vadal.local/posts"><em>http://vadal.local/posts</em></a></blockquote><p>Increase the vusers replicas to 2.</p><blockquote><em>kc scale deployment/vusers -n vadal — replicas=2</em></blockquote><p>Make a request again.</p><p>The two calls to vuser from vposts are being load balanced between the two pods, nice:</p><p><strong>Pod 1</strong></p><blockquote><em>Hibernate: select user0_.id as id1_1_0_, user0_.name as name2_1_0_, user0_.role_id as role_id3_1_0_, role1_.id as id1_0_1_, role1_.role as role2_0_1_ from user user0_ left outer join role role1_ on user0_.role_id=role1_.id where user0_.id=?</em></blockquote><blockquote><em>GET /u/3 HTTP/1.1&quot; 200 — “-” “-” 0 288 12 11 “-” “Java/1.8.0_252” “91cc29b8-c3c8–9408-b3a4-c20d1fa236e0” “vusers.vadal.svc.cluster.local” “127.0.0.1:7777” inbound|80||vusers.vadal.svc.cluster.local 127.0.0.1:37020 10.1.1.43:7777 10.1.1.57:48222 outbound_.80_._.vusers.vadal.svc.cluster.local default</em></blockquote><p><strong>Pod 2</strong></p><blockquote><em>Hibernate: select user0_.id as id1_1_0_, user0_.name as name2_1_0_, user0_.role_id as role_id3_1_0_, role1_.id as id1_0_1_, role1_.role as role2_0_1_ from user user0_ left outer join role role1_ on user0_.role_id=role1_.id where user0_.id=?</em></blockquote><blockquote><em>GET /u/4 HTTP/1.1&quot; 200 — “-” “-” 0 289 18 17 “-” “Java/1.8.0_252” “c235f5f2–7d54–9473–91a2–55909f1cc0c8” “vusers.vadal.svc.cluster.local” “127.0.0.1:7777” inbound|80||vusers.vadal.svc.cluster.local 127.0.0.1:37024 10.1.1.58:7777 10.1.1.57:58646 outbound_.80_._.vusers.vadal.svc.cluster.local default</em></blockquote><p>Let’s increase the replicas for vposts as well.</p><blockquote><em>kc scale deployment/vposts -n vadal — replicas=2</em></blockquote><p>Lets apply some load with this shell script:</p><pre># /bin/bash<br>for i in {1..10}<br>do<br>  curl -s http://vadal.local/posts &amp;<br>done</pre><p>You can see the services visually interacting in Kiali. Nice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UfxGQ3eclVl7nLkX.png" /></figure><p>You can also check the request traces with the request-id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cqjX3Wbo8k45TS4T.png" /></figure><h3>Jaeger</h3><p>With istioctl installed (which we did <a href="https://medium.com/@lightphos/istio-with-kubernetes-b898be1014d7">previously</a>) we can also look at traces with Jaeger.</p><blockquote><em>istioctl dashboard jaeger</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FrEJV_wBE4RlrIiJ.png" /></figure><h3>Grafana</h3><p>We can view volumetrics etc from Grafana, from our previous installation:</p><p><a href="http://localhost:30003/?orgId=1">http://localhost:30003/?orgId=1</a></p><p>Kiali may give an error so change the Grafana details in ConfigMaps for Kiali:</p><pre>grafana:<br>    url: http://localhost:30003<br>    in_cluster_url: http://grafana.istio-system:3000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PEwJoFMyVrGr8QaY.png" /></figure><h3>Conclusion</h3><p>With Istio and Kiali we can see the service REST communication and observe these visually with it providing request traffic rates, tracing and logs. Very useful. We can also look at service to service request tracing with Jaeger.</p><p>In addition there is a Grafana view providing details of the service cluster and the Isitio mesh as a whole.</p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/istio-kubernetes-and-inter-service-communication/"><em>https://blog.ramjee.uk</em></a><em> on July 15, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=743af225c24f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/observability-with-istio-kiali-and-grafana-in-kubernetes-and-spring-boot-743af225c24f">Observability With Istio, Kiali, and Grafana in Kubernetes and Spring Boot</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Istio API Security with Keycloak in Kubernetes]]></title>
            <link>https://medium.com/actual-tech/istio-api-security-with-keycloak-in-kubernetes-88c2a6f6e0bd?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/88c2a6f6e0bd</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Wed, 15 Jul 2020 15:22:19 GMT</pubDate>
            <atom:updated>2024-02-03T17:03:03.055Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*v59VF4tTWH2zFPZK.png" /></figure><p>See also:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FSWfeNY8nJKg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSWfeNY8nJKg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FSWfeNY8nJKg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a30c4b97af2bdf4abeb77fac1438e9b8/href">https://medium.com/media/a30c4b97af2bdf4abeb77fac1438e9b8/href</a></iframe><p>Having added<a href="https://medium.com/@lightphos/istio-api-security-in-kubernetes-with-jwt-a9848f228bab"> JWT </a>directly into Istio API service security, we now instead use Keycloak to act as our OIDC/JWT provider.</p><h3>Install Keycloak</h3><blockquote><em>helm repo add codecentric </em><a href="https://codecentric.github.io/helm-charts"><em>https://codecentric.github.io/helm-charts</em></a><em><br>helm install codecentric/keycloak --name keycloak</em></blockquote><blockquote><em>NAME: keycloak<br>NAMESPACE: default<br>STATUS: DEPLOYED</em></blockquote><blockquote><em>RESOURCES:<br>==&gt; v1/ConfigMap<br>NAME DATA AGE<br>keycloak-sh 1 0s<br>keycloak-startup 1 0s<br>keycloak-test 1 0s</em></blockquote><blockquote><em>==&gt; v1/Pod(related)<br>NAME READY STATUS RESTARTS AGE<br>keycloak-0 0/1 ContainerCreating 0 0s</em></blockquote><blockquote><em>==&gt; v1/Secret<br>NAME TYPE DATA AGE<br>keycloak-db Opaque 2 0s<br>keycloak-http Opaque 1 0s</em></blockquote><blockquote><em>==&gt; v1/Service<br>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE<br>keycloak-headless ClusterIP None 80/TCP,8443/TCP 0s<br>keycloak-http ClusterIP 10.96.125.143 80/TCP,8443/TCP 0s</em></blockquote><blockquote><em>==&gt; v1/StatefulSet<br>NAME READY AGE<br>keycloak 0/1 0s</em></blockquote><blockquote><em>NOTES:<br>Keycloak can be accessed:<br>Within your cluster, at the following DNS name at port 80:<br></em><strong><em>keycloak-http.default.svc.cluster.local</em></strong></blockquote><h3>Add Realm and User to Keycloak</h3><p>To access the Keycloak GUI carry out the following steps.</p><p>Edit the keycloak-http service and change ClusterIP to NodePort and add nodePort: say 30006 (assuming it doesn’t clash with anything you have already).</p><blockquote><em>kubectl edit svc/keycloak-http</em></blockquote><pre>spec:<br>  ports:<br>    - name: http<br>      protocol: TCP<br>      port: 80<br>      targetPort: http<br>      nodePort: 30006<br>    - name: https<br>      protocol: TCP<br>      port: 8443<br>      targetPort: https<br>      nodePort: 30090<br>  selector:<br>    app.kubernetes.io/instance: keycloak<br>    app.kubernetes.io/name: keycloak<br>  clusterIP: 10.98.46.34<br>  type: NodePort</pre><p>Login to <a href="http://localhost:30006/">http://localhost:30006</a></p><p>Username: keycloak<br>Initial password:</p><blockquote><em>kubectl get secret — namespace default keycloak-http -o jsonpath=”{.data.password}” | base64 --decode; echo</em></blockquote><p>Set up a realm (vadal), a client (vadal), a user (vadal) with password (vadal) and a role (vadaluser) assigned to vadal user (see <a href="https://labs.consol.de/development/2020/05/07/istio-and-keycloak.html">https://labs.consol.de/development/2020/05/07/istio-and-keycloak.html</a> ).</p><p>You should end up with something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6Uj-715MLqyQlklQ.png" /></figure><p>Configure Istio authentication and authorisation.</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: security.istio.io/v1beta1<br>kind: &quot;RequestAuthentication&quot;<br>metadata:<br>  name: vecho-jwt<br>  namespace: vadal<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vecho<br>  jwtRules:<br>    - outputPayloadToHeader: vadaltoken<br>      issuer: &quot;http://localhost:30006/auth/realms/vadal&quot;<br>      jwksUri: &quot;http://keycloak-http.default.svc.cluster.local/auth/realms/vadal/protocol/openid-connect/certs&quot;<br><br>---<br><br>apiVersion: security.istio.io/v1beta1<br>kind: AuthorizationPolicy<br>metadata:<br>  name: vecho-get<br>  namespace: vadal<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vecho<br>  action: ALLOW<br>  rules:<br>  - to:<br>    - operation:<br>        methods: [&quot;GET&quot;]<br>    when:<br>      - key: request.auth.claims[iss]<br>        values: [&quot;http://localhost:30006/auth/realms/vadal&quot;]<br>EOF</pre><p>Note the issuer and jwksUri settings.</p><p>Get a token from keycloak.</p><pre>curl \ -sk \ --data &quot;username=vadal&amp;password=vadal&amp;grant_type=password&amp;client_id=vadal&quot; \ http://localhost:30006/auth/realms/vadal/protocol/openid-connect/token | jq &quot;.access_token&quot;</pre><p>(if you do not have jq installed, then remove | jq “.access_token” from the query above, and pickout just the access_token part)</p><p>{“access_token”:”eyJhbGciO <em>iJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJuZEkydGFPcHViZjltQ2RSNEhLRkJ4dXYxNGl0Q1d</em> xTkxsWmR0X19HaWlNIn0.eyJleHAiOjE1OTQ2ODIzMjcsImlhdCI6MTU5NDY4MjAyNywianRpIjoiOTMwZGM5YmEtNDllZi00OWM5LTliOGEtOGJmNWUwY2M1YjcwIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDozMDAwNi9hdXRoL3JlYWxtcy92YWRhbCIsImF1ZCI6….}</p><p>NOTE: Need to use it before the <strong>expiry</strong> time.</p><blockquote><em>TOKEN=eyJhbGciOiJSUzI1….</em></blockquote><blockquote><em>curl -i </em><a href="http://vadal.local/echo"><em>http://vadal.local/echo</em></a><em> -H “Authorization: Bearer $TOKEN”<br>HTTP/1.1 200 OK<br>content-type: application/json<br>date: Mon, 13 Jul 2020 23:36:53 GMT<br>x-envoy-upstream-service-time: 334<br>server: istio-envoy<br>transfer-encoding: chunked</em></blockquote><blockquote><em>{“timestamp”:”2020–07–13T23:36:53.675&quot;,”headers”:{“host”:”vadal.local”,”user-agent”:”curl/7.64.1&quot;,”accept”:”</em>/<em>”,”x-b3-sampled”:”1&quot;,”x-forwarded-proto”:”http”,”x-request-id”:”e250b31a-903e-9ca4-ae1a-edde00f97718&quot;,”x-envoy-original-path”:”/echo”,”content-length”:”0&quot;,”x-envoy-internal”:”true”,”x-forwarded-client-cert”:”By=spiffe://cluster.local/ns/vadal/sa/default;Hash=cd101b753b794f67a67f25bbcdcb391a7505d52f24e0cd340c9365d05c241a80;Subject=””;URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account”,”vadaltoken”:”eyJleHAiOjE1OTQ2ODM2ODcsImlhdCI6MTU5NDY4MzM4NywianRpIjoiYzhjZTRiNGUtMzVjMC00NzQ1LTk3M2YtNTQzMjZlMzM0Njc3IiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDozMDAwNi9hdXRoL3JlYWxtcy92YWRhbCIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiI5MDNhMDUwMS03Mjc5LTQxOTMtYjkxYS03NGI5MjJmMDMyMjQiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJ2YWRhbCIsInNlc3Npb25fc3RhdGUiOiIxM2YwOWM3Yy1iYWY3LTQ0NTMtYTVmNC1jMmEwMWExNjlhYWMiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHBzOi8vd3d3LmtleWNsb2FrLm9yZyJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsidmFkYWx1c2VyIiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoicHJvZmlsZSBlbWFpbCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwibmFtZSI6InZhZGFsIGNsb3VkIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidmFkYWwiLCJnaXZlbl9uYW1lIjoidmFkYWwiLCJmYW1pbHlfbmFtZSI6ImNsb3VkIn0&quot;,”x-b3-traceid”:”db81914bb9612948cb7d38748d119f8e”,”x-b3-spanid”:”daebf61620cb8212&quot;,”x-b3-parentspanid”:”cb7d38748d119f8e”}}</em></blockquote><p>If it has expired you’ll get the following and you’ll need a new token.</p><p>HTTP/1.1 401 Unauthorized<br>content-length: 14<br>content-type: text/plain<br>date: Mon, 13 Jul 2020 23:55:15 GMT<br>server: istio-envoy<br>x-envoy-upstream-service-time: 1</p><p>Jwt is expired</p><p>Nice. With KeyCloak you can manage your token delivery and other parameters.</p><h3>Conclusion</h3><p>We installed keycloak, added our client, user credentials and realm to it. It then was used to provide us with a JWT which we were able to secure our API access. We had Istio authorisation defined to connect to keycloak to verify access.</p><p>Note: This keycloak installation used H2 db for it’s persistence so the details will be lost once shutdown.</p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/istio-api-security-with-keycloak-in-kubernetes/"><em>https://blog.ramjee.uk</em></a><em> on July 15, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88c2a6f6e0bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/actual-tech/istio-api-security-with-keycloak-in-kubernetes-88c2a6f6e0bd">Istio API Security with Keycloak in Kubernetes</a> was originally published in <a href="https://medium.com/actual-tech">actual-tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Istio API Security in Kubernetes With JWT]]></title>
            <link>https://medium.com/swlh/istio-api-security-in-kubernetes-with-jwt-a9848f228bab?source=rss-b8e9a3e517f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9848f228bab</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[jwt]]></category>
            <dc:creator><![CDATA[Lightphos]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 20:59:07 GMT</pubDate>
            <atom:updated>2024-02-03T17:17:29.145Z</atom:updated>
            <content:encoded><![CDATA[<h4>istio api security</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/0*pVW_qtWcqKkEhSLK.png" /></figure><p>See also:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrZxaffzjyUM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrZxaffzjyUM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrZxaffzjyUM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/508f3692cffd5dc3dffe8f8068493fa9/href">https://medium.com/media/508f3692cffd5dc3dffe8f8068493fa9/href</a></iframe><p><a href="https://medium.com/@lightphos/istio-with-kubernetes-b898be1014d7">Earlier</a> we installed Istio and deployed our echo service ‘vecho’ into K8s.</p><p>This should be up and running, if we call the endpoint.</p><blockquote><em>curl -i vadal.local/echo</em></blockquote><p>We now want to secure access to this service like we did with <a href="https://levelup.gitconnected.com/kong-api-security-in-kubernetes-with-api-key-and-jwt-17985135a1a6">Kong</a>.</p><p>For security in Istio, we need to ensure the following is set for the service or else you will get a 503 error.</p><blockquote><em>kubectl edit svc/vecho -n vadal</em></blockquote><p>Make sure it has <strong>name: http </strong>set</p><pre>ports:<br>  - name: http<br>    port: 80<br>    protocol: TCP<br>    targetPort: 8080</pre><p>Add the following authorization policy. This enforces the rule that only GET requests can access the service.</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: security.istio.io/v1beta1<br>kind: AuthorizationPolicy<br>metadata:<br>  name: vecho-get<br>  namespace: vadal<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vecho<br>  action: ALLOW<br>  rules:<br>  - to:<br>    - operation:<br>        methods: [&quot;GET&quot;]<br>EOF</pre><blockquote><em>curl -i vadal.local/echo -X POST<br>HTTP/1.1 403 Forbidden<br>content-length: 19<br>content-type: text/plain<br>date: Sun, 12 Jul 2020 23:05:03 GMT<br>server: istio-envoy<br>x-envoy-upstream-service-time: 3<br>RBAC: access denied</em></blockquote><blockquote><em>curl -i vadal.local/echo -X GET<br>HTTP/1.1 200 OK<br>content-type: application/json<br>date: Sun, 12 Jul 2020 23:05:38 GMT<br>x-envoy-upstream-service-time: 8<br>server: istio-envoy<br>transfer-encoding: chunked<br>{“timestamp”:”2020–07–12T23:05:38.318&quot;,”headers”:{“host”:”vadal.local”,”user-agent”:”curl/7.64.1&quot;,”accept”:”</em>/<em>”,”x-b3-sampled”:”1&quot;,”x-forwarded-proto”:”http”,”x-request-id”:”6c0ded60–6b20–9eea-b599–1392d1053e56&quot;,”x-envoy-original-path”:”/echo”,”content-length”:”0&quot;,”x-envoy-internal”:”true”,”x-forwarded-client-cert”:”By=spiffe://cluster.local/ns/vadal/sa/default;Hash=aae1e29c7a34b9f1f614d868f212f936019bd2caa7560221224ef70578705c31;Subject=””;URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account”,”x-b3-traceid”:”c11e0dcd7b8727b19adf3e7a5dd5b589&quot;,”x-b3-spanid”:”294e70a066ee29a7&quot;,”x-b3-parentspanid”:”9adf3e7a5dd5b589&quot;}}</em></blockquote><p>All good.</p><h3>Key Header Access</h3><p>Here we restrict access using a key in the header. Apply the following.</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: security.istio.io/v1beta1<br>kind: AuthorizationPolicy<br>metadata:<br>  name: vecho-get<br>  namespace: vadal<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vecho<br>  action: ALLOW<br>  rules:<br>  - to:<br>    - operation:<br>        methods: [&quot;GET&quot;]<br>    when:<br>      - key: request.headers[x-vadal-key]<br>        values: [&quot;secret&quot;]<br>EOF</pre><p>Access will be denied unless you provide the correct header and value.</p><blockquote><em>curl -i </em><a href="http://vadal.local/echo"><em>http://vadal.local/echo</em></a><em> -H “x-vadal-key:secret”</em></blockquote><h3>JWT Access</h3><p>In Istio JWT Access has two parts, a RequestAuthentication and a AuthorizationPolicy like the above. The JWT settings are defined with JSON Web Key Sets (JWKS).</p><p>First we create a JWT test token (RS256) which we will use to secure our API.</p><p><a href="https://jwt.io/#debugger-io?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0.fZjUjMZA4Zk06HMwUhWWyN_9390eyPq1NHc8PkCD_9ZX2N6hqoPyoKeoUJlz2-914F-zSYa31YF1Z0tLPkf8oUCoC-8NaUmgcpB178g957b0ugg39mZGRi2DDiJSPPaQ1S_0xfHjQQwl46S0UoNnDDzcFuEngZ_Rnpviyoi-LZ4CcwamYP19N-WmXOZvESnPJ9MhSzudBWArLAarFQ74tg6Lmf3GWRuTKzdECd29IBq-CdQvdP6YxsMvceoxZXfy76jrRLbFkjfEn6fT_SWPL-FN3zX-emaiYGyfFGB9nmOjgCph0F20oy5Gf5ffEVxM4uzMerzheawqtg3HDResYQ&amp;publicKey=-----BEGIN%20PUBLIC%20KEY-----%0AMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnzyis1ZjfNB0bBgKFMSv%0AvkTtwlvBsaJq7S5wA%2BkzeVOVpVWwkWdVha4s38XM%2Fpa%2Fyr47av7%2Bz3VTmvDRyAHc%0AaT92whREFpLv9cj5lTeJSibyr%2FMrm%2FYtjCZVWgaOYIhwrXwKLqPr%2F11inWsAkfIy%0AtvHWTxZYEcXLgAXFuUuaS3uF9gEiNQwzGTU1v0FqkqTBr4B8nW3HCN47XUu0t8Y0%0Ae%2Blf4s4OxQawWD79J9%2F5d3Ry0vbV3Am1FtGJiJvOwRsIfVChDpYStTcHTCMqtvWb%0AV6L11BWkpzGXSW4Hv43qa%2BGSYOD2QU68Mb59oSk2OB%2BBtOLpJofmbGEGgvmwyCI9%0AMwIDAQAB%0A-----END%20PUBLIC%20KEY-----">https://jwt.io/#debugger-io?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0.fZjUjMZA4Zk06HMwUhWWyN_9390eyPq1NHc8PkCD_9ZX2N6hqoPyoKeoUJlz2-914F-zSYa31YF1Z0tLPkf8oUCoC-8NaUmgcpB178g957b0ugg39mZGRi2DDiJSPPaQ1S_0xfHjQQwl46S0UoNnDDzcFuEngZ_Rnpviyoi-LZ4CcwamYP19N-WmXOZvESnPJ9MhSzudBWArLAarFQ74tg6Lmf3GWRuTKzdECd29IBq-CdQvdP6YxsMvceoxZXfy76jrRLbFkjfEn6fT_SWPL-FN3zX-emaiYGyfFGB9nmOjgCph0F20oy5Gf5ffEVxM4uzMerzheawqtg3HDResYQ&amp;publicKey=-----BEGIN PUBLIC KEY — — — MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnzyis1ZjfNB0bBgKFMSv vkTtwlvBsaJq7S5wA%2BkzeVOVpVWwkWdVha4s38XM%2Fpa%2Fyr47av7%2Bz3VTmvDRyAHc aT92whREFpLv9cj5lTeJSibyr%2FMrm%2FYtjCZVWgaOYIhwrXwKLqPr%2F11inWsAkfIy tvHWTxZYEcXLgAXFuUuaS3uF9gEiNQwzGTU1v0FqkqTBr4B8nW3HCN47XUu0t8Y0 e%2Blf4s4OxQawWD79J9%2F5d3Ry0vbV3Am1FtGJiJvOwRsIfVChDpYStTcHTCMqtvWb V6L11BWkpzGXSW4Hv43qa%2BGSYOD2QU68Mb59oSk2OB%2BBtOLpJofmbGEGgvmwyCI9 MwIDAQAB — — -END PUBLIC KEY — — -</a> <a href="https://russelldavies.github.io/jwk-creator/">https://russelldavies.github.io/jwk-creator/</a></p><p>Now we need the corresponding JWK, copy the <strong>public </strong>key to this site:</p><p><a href="https://russelldavies.github.io/jwk-creator/">https://russelldavies.github.io/jwk-creator/</a></p><p>Copy the converted JWK to the block below within keys: [], as shown and also define the AuthorizationPolicy to now expect iss to be vadal.</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: security.istio.io/v1beta1<br>kind: &quot;RequestAuthentication&quot;<br>metadata:<br>  name: vecho-jwt<br>  namespace: vadal<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vecho<br>  jwtRules:<br>    - outputPayloadToHeader: vadaltoken<br>      issuer: &quot;vadal&quot;<br>      jwks: |<br>        {<br>          keys: [<br>            {<br>              &quot;kty&quot;: &quot;RSA&quot;,<br>              &quot;n&quot;: &quot;nzyis1ZjfNB0bBgKFMSvvkTtwlvBsaJq7S5wA-kzeVOVpVWwkWdVha4s38XM_pa_yr47av7-z3VTmvDRyAHcaT92whREFpLv9cj5lTeJSibyr_Mrm_YtjCZVWgaOYIhwrXwKLqPr_11inWsAkfIytvHWTxZYEcXLgAXFuUuaS3uF9gEiNQwzGTU1v0FqkqTBr4B8nW3HCN47XUu0t8Y0e-lf4s4OxQawWD79J9_5d3Ry0vbV3Am1FtGJiJvOwRsIfVChDpYStTcHTCMqtvWbV6L11BWkpzGXSW4Hv43qa-GSYOD2QU68Mb59oSk2OB-BtOLpJofmbGEGgvmwyCI9Mw&quot;,<br>              &quot;e&quot;: &quot;AQAB&quot;,<br>              &quot;alg&quot;: &quot;RS256&quot;,<br>              &quot;use&quot;: &quot;sig&quot;<br>            }<br>          ]<br>        }<br><br>---<br>apiVersion: security.istio.io/v1beta1<br>kind: AuthorizationPolicy<br>metadata:<br>  name: vecho-get<br>  namespace: vadal<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vecho<br>  action: ALLOW<br>  rules:<br>  - to:<br>    - operation:<br>        methods: [&quot;GET&quot;]<br>    when:<br>      - key: request.auth.claims[iss]<br>        values: [&quot;vadal&quot;]<br>EOF</pre><p>We have added RequestAuthentication and added to AuthorizationPolicy the when clause which expects an iss equal to vadal.</p><blockquote><em>curl -i vadal.local/echo<br>HTTP/1.1 403 Forbidden<br>content-length: 19<br>content-type: text/plain<br>date: Sun, 12 Jul 2020 23:08:17 GMT<br>server: istio-envoy<br>x-envoy-upstream-service-time: 6</em></blockquote><blockquote><em>RBAC: access denied</em></blockquote><p>Now use the token above:</p><blockquote><em>TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0.fZjUjMZA4Zk06HMwUhWWyN_9390eyPq1NHc8PkCD_9ZX2N6hqoPyoKeoUJlz2–914F-zSYa31YF1Z0tLPkf8oUCoC-8NaUmgcpB178g957b0ugg39mZGRi2DDiJSPPaQ1S_0xfHjQQwl46S0UoNnDDzcFuEngZ_Rnpviyoi-LZ4CcwamYP19N-WmXOZvESnPJ9MhSzudBWArLAarFQ74tg6Lmf3GWRuTKzdECd29IBq-CdQvdP6YxsMvceoxZXfy76jrRLbFkjfEn6fT_SWPL-FN3zX-emaiYGyfFGB9nmOjgCph0F20oy5Gf5ffEVxM4uzMerzheawqtg3HDResYQ</em></blockquote><blockquote><em>curl -i </em><a href="http://vadal.local/echo"><em>http://vadal.local/echo</em></a><em> -H “Authorization: Bearer $TOKEN”</em></blockquote><blockquote><em>HTTP/1.1 200 OK<br>content-type: application/json<br>date: Mon, 13 Jul 2020 00:12:59 GMT<br>x-envoy-upstream-service-time: 8<br>server: istio-envoy<br>transfer-encoding: chunked</em></blockquote><blockquote><em>{“timestamp”:”2020–07–13T00:32:42.107&quot;,”headers”:{“host”:”vadal.local”,”user-agent”:”curl/7.64.1&quot;,”accept”:”</em>/<em>”,”authorization”:”Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0.fZjUjMZA4Zk06HMwUhWWyN_9390eyPq1NHc8PkCD_9ZX2N6hqoPyoKeoUJlz2–914F-zSYa31YF1Z0tLPkf8oUCoC-8NaUmgcpB178g957b0ugg39mZGRi2DDiJSPPaQ1S_0xfHjQQwl46S0UoNnDDzcFuEngZ_Rnpviyoi-LZ4CcwamYP19N-WmXOZvESnPJ9MhSzudBWArLAarFQ74tg6Lmf3GWRuTKzdECd29IBq-CdQvdP6YxsMvceoxZXfy76jrRLbFkjfEn6fT_SWPL-FN3zX-emaiYGyfFGB9nmOjgCph0F20oy5Gf5ffEVxM4uzMerzheawqtg3HDResYQ”,”x-b3-sampled”:”1&quot;,”x-forwarded-proto”:”http”,”x-request-id”:”54b2bab0–8b7b-90d5-ad4d-d5c61ddb5c17&quot;,”x-envoy-original-path”:”/echo”,”content-length”:”0&quot;,”x-envoy-internal”:”true”,”x-forwarded-client-cert”:”By=spiffe://cluster.local/ns/vadal/sa/default;Hash=aae1e29c7a34b9f1f614d868f212f936019bd2caa7560221224ef70578705c31;Subject=””;URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account”,”</em><strong><em>vadaltoken</em></strong><em>”:”eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0&quot;,”x-b3-traceid”:”df7bf539adf2fe23035466d917e4b60c”,”x-b3-spanid”:”b937e924a214b861&quot;,”x-b3-parentspanid”:”035466d917e4b60c”}}</em></blockquote><p>Access is now controlled by JWT RS256.</p><p>We can also use a HS256 JWT in a similar way.</p><p>Generate JWK from here <a href="https://mkjwk.org/">https://mkjwk.org/</a></p><p>Add a new RequestAuthentication with a metadata name of vadal-jwt-oct and the following keys copied from the site above.</p><pre>{<br>    &quot;keys&quot;: [<br>        {<br>            &quot;kty&quot;: &quot;oct&quot;,<br>            &quot;use&quot;: &quot;sig&quot;,<br>            &quot;kid&quot;: &quot;vadal&quot;,<br>            &quot;k&quot;: &quot;_kR1V8tTZ6z4-u2sQ3B4BfAx96773EHZQMi5g6baUQXsxHfSLU5EucNDycQqW3QkA2V0oXOLn4zoj6nSehJz-pidWVjP3-QGOZcj4lU5B2bU0nzjUNwgvTQM0h2ooyhlG8zOgaSPbmXYRh9eXlLVK2Zn8GFBk-YRciTejrkMpP1bLw70LB5rHtMwSY-hUJ-xEx1v7GeibNCglVp5BnAqXZM47fEhFxxcz1vw7sNnBM-s_sV58Hg4tY0nSKO7-iMCuCs2XAPfcxVY8JaVwZjrN9hLITsqJsvQlDj48uB6W1f4T94Xydc5cCjKsXkSk169ii5gNJLZFaWPCNupk1FFSA&quot;,<br>            &quot;alg&quot;: &quot;HS256&quot;<br>        }<br>    ]<br>}</pre><p>To obtain the corresponding HS256 JWT we need to grab the K value.</p><p><a href="https://jwt.io/#debugger-io?token=eyJhbGciOiJIUzI1NiIsImtpZCI6InZhZGFsIiwidHlwIjoiSldUIn0.eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0.wKGe7fJG4Vp0ZDXtf0RaHyXTUL0tnWGA10ptGlB1Cp4">https://jwt.io/#debugger-io?token=eyJhbGciOiJIUzI1NiIsImtpZCI6InZhZGFsIiwidHlwIjoiSldUIn0.eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0.wKGe7fJG4Vp0ZDXtf0RaHyXTUL0tnWGA10ptGlB1Cp4</a></p><p>The k value -&gt; _kR1V… needs to go into the secret field in the link below (and the option ‘secret is based 64’ selected)</p><p>Set a new variable with the resulting token.</p><blockquote><em>TOKENH=eyJhbGciOiJIUzI1NiIsImtpZCI6InZhZGFsIiwidHlwIjoiSldUIn0.eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0.wKGe7fJG4Vp0ZDXtf0RaHyXTUL0tnWGA10ptGlB1Cp4</em></blockquote><blockquote><em>curl -i </em><a href="http://vadal.local/echo"><em>http://vadal.local/echo</em></a><em> -H “Authorization: Bearer $TOKENH”</em></blockquote><blockquote><em>HTTP/1.1 200 OK<br>content-type: application/json<br>date: Mon, 13 Jul 2020 01:07:04 GMT<br>x-envoy-upstream-service-time: 6<br>server: istio-envoy<br>transfer-encoding: chunked</em></blockquote><blockquote><em>{“timestamp”:”2020–07–13T01:07:04.348&quot;,”headers”:{“host”:”vadal.local”,”user-agent”:”curl/7.64.1&quot;,”accept”:”</em>/<em>”,”x-b3-sampled”:”1&quot;,”x-forwarded-proto”:”http”,”x-request-id”:”097c3aa6–5284–993b-89be-167556119b13&quot;,”x-envoy-original-path”:”/echo”,”content-length”:”0&quot;,”x-envoy-internal”:”true”,”x-forwarded-client-cert”:”By=spiffe://cluster.local/ns/vadal/sa/default;Hash=aae1e29c7a34b9f1f614d868f212f936019bd2caa7560221224ef70578705c31;Subject=””;URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account”,”vadaltoken”:”eyJpc3MiOiJ2YWRhbCIsImlhdCI6MTUxNjIzOTAyMn0&quot;,”x-b3-traceid”:”c658d2e664c825a7435899abdefffd7c”,”x-b3-spanid”:”fee9e51531bd63a6&quot;,”x-b3-parentspanid”:”435899abdefffd7c”}}</em></blockquote><p>We now have JWT HS256 access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3U5opb2LfIyk-WBN.png" /></figure><p>As can be seen above, the one authorization policy can have multiple separate request authentication definitions.</p><h3>Conclusion</h3><p>We have added an API Header key, a RS256 as well as a HS256 JWT to control access to our service.</p><p>This is a bit more involved than <a href="https://levelup.gitconnected.com/kong-api-security-in-kubernetes-with-api-key-and-jwt-17985135a1a6">Kong</a> due to its use of JWKS, but works in the same way. We saw how Authorisation policies could be applied to workloads directly.</p><h3>Further Details</h3><p><a href="https://istio.io/latest/docs/concepts/security/">https://istio.io/latest/docs/concepts/security/</a> <a href="https://tools.ietf.org/html/rfc7517#section-4.3">https://tools.ietf.org/html/rfc7517#section-4.3</a> <a href="https://mkjwk.org/">https://mkjwk.org/</a> <a href="https://russelldavies.github.io/jwk-creator/">https://russelldavies.github.io/jwk-creator/</a> <a href="https://www.keycloak.org/">https://www.keycloak.org/</a></p><p><em>Originally published at </em><a href="https://blog.ramjee.uk/istio-api-security-in-kubernetes-with-jwt/"><em>https://blog.ramjee.uk</em></a><em> on July 13, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9848f228bab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/istio-api-security-in-kubernetes-with-jwt-a9848f228bab">Istio API Security in Kubernetes With JWT</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>