<?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 Anaïs Urlichs on Medium]]></title>
        <description><![CDATA[Stories by Anaïs Urlichs on Medium]]></description>
        <link>https://medium.com/@anaisurl?source=rss-2ac6b7c2915b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5S-60-RXzuELhUxHWwViuQ.png</url>
            <title>Stories by Anaïs Urlichs on Medium</title>
            <link>https://medium.com/@anaisurl?source=rss-2ac6b7c2915b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 15:42:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anaisurl/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[Full Tutorial: Monitoring and Troubleshooting stack with Prometheus, Grafana, Loki and Komodor]]></title>
            <link>https://anaisurl.medium.com/full-tutorial-monitoring-and-troubleshooting-stack-with-prometheus-grafana-loki-and-komodor-a0d600cd9a2e?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0d600cd9a2e</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[kuberentes]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Tue, 07 Dec 2021 14:45:29 GMT</pubDate>
            <atom:updated>2021-12-07T14:45:29.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfd8Yl7gyT7Ycey2YivouQ.png" /></figure><p>Komodor is a troubleshooting platform for Kubernetes-based environments. It tracks changes and events across the entire system’s stack and provides the needed context to troubleshoot issues in our Kubernetes cluster efficiently.</p><p>The previous blog post provided a comprehensive overview of the platform and its use. In this blog post, we will see the process of troubleshooting an application with Komodor after setting up our monitoring stack on our Kubernetes cluster. If you would like to follow along, please sign up to Komodor. The introductory blog post guides you through the process.</p><p><strong>Introductory blog post</strong>: <a href="https://anaisurl.com/simplify-troubleshooting/">https://anaisurl.com/simplify-troubleshooting/</a></p><p><strong>Introductory video tutorial</strong>: <a href="https://youtu.be/9eC24tzJxSY">https://youtu.be/9eC24tzJxSY</a></p><h3>The Plan</h3><p>I like to provide “real-world” examples to showcase the value of tools such as Komodor. In this scenario, we are going to have our Monitoring Stack with Prometheus, Grafana, and Loki installed on our cluster. Next, we are going to deploy an application and a client.</p><p>These two services are going to communicate with each other. The client is going to “ping” our application and the application is going to respond with a “pong”. This will result in a ping-pong communication between both applications.</p><p>Next, we are going to update the container image of our application. This deployment will simulate updates to our code “gone wrong”. Our monitoring stack will be used to see that our application is not behaving correctly and get notified of potential errors in the first place. Komodor will be our tool of choice to debug our running application and fix the error.</p><p>If you prefer the video tutorial instead of the written guide, you can follow along here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FY7W-VYCL4pw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DY7W-VYCL4pw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FY7W-VYCL4pw%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/2f90857bcd0257533bc25963627ed156/href">https://medium.com/media/2f90857bcd0257533bc25963627ed156/href</a></iframe><h3>Setup</h3><p>We are currently running a Civo Kubernetes cluster. On the cluster, we have several different resources installed, including:</p><ul><li>Our Monitoring Stack with Prometheus and Grafana</li><li>The Komodor Agent</li><li>A Demo Application</li></ul><p><strong>Prerequisites</strong></p><p>Before we get started, we need a Kubernetes cluster that will host our applications. In our case, we are going to be using <a href="https://www.civo.com/">Civo Cloud</a> since it is fast and cost-effective. You can find a guide on how to get started with Civo Kubernetes <a href="https://www.civo.com/learn/how-to-launch-civo-kubernetes-cluster">here</a>. However, feel free to use any other Kubernetes cluster instead.</p><p>Before heading to the next section, you should be able to connect to your Kubernetes cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/0*0xeBd9Mf-xqx1sAR.png" /></figure><p>Additionally, we are going to use Helm throughout the tutorial to install and update resources running within our cluster. Helm is a Kubernetes package manager (think about it like npm for Kubernetes). Several Kubernetes based tools require lots and lots of YAML manifests. Helm makes it possible to bundle those together into single Helm Charts. If you are completely new to Helm, I highly suggest you have a look at one of my previous tutorials:</p><p>You can install Helm from <a href="https://helm.sh/">this link</a>.</p><h3>Our Monitoring Stack with Prometheus and Grafana</h3><p>Next, we want to deploy our monitoring stack to our demo cluster. For Prometheus and Grafana, we are going to use the <a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack">Prometheus stack operator</a>. Please don’t get overwhelmed by the repository, I am going to walk you through all the steps required to set up the operator through the Helm Chart.</p><p>First, we have to add the operator repository to our helm cli. Note that the Prometheus stack operator Helm chart is within the prometheus-community repository. No need to get confused by the naming convention.</p><p>Follow these commands:</p><pre>helm repo add prometheus-community https://prometheus-community.github.io/helm-charts</pre><p>Before we go ahead and deploy the Helm Chart to our Kubernetes cluster, we want to make a few slight adjustments. These are going to be stored in a values.yaml file.</p><p>Create the values.yaml file:</p><pre>touch values.yaml</pre><p>Here is how our values.yaml file will look like:</p><pre>prometheus:</pre><pre>prometheusSpec:</pre><pre>serviceMonitorSelectorNilUsesHelmValues: false</pre><pre>serviceMonitorSelector: {}</pre><pre>serviceMonitorNamespaceSelector: {}</pre><pre>grafana:</pre><pre>sidecar:</pre><pre>datasources:</pre><pre>defaultDatasourceEnabled: true</pre><pre>additionalDataSources:</pre><pre>- name: Loki</pre><pre>type: loki</pre><pre>url: http://loki-loki-distributed-query-frontend.monitoring:3100</pre><p>Note: Please see this Git Repository for the proper indentation.</p><p><strong>What is this content based on?</strong></p><p>Within the <a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack">Prometheus stack operator Helm Chart</a> is a values.yaml file. This file will tell Helm how to configure the Helm Chart upon installation. If we do not overwrite the value within the file, all the default values will get deployed. However, with the default values, we will not be able to connect Prometheus to our application. Thus, we are going to create our own values.yaml file and overwrite some of the values in the default one.</p><p>Helm provides a really handy flag to pass in a custom values file through ‘ — values’. Note that we are going to install all of our monitoring resources into a monitoring namespace. You can create the namespace through the following command:</p><pre>kubectl create ns monitoring</pre><p>We can now run the following command to install the Helm Chart:</p><pre>helm install prom prometheus-community/kube-prometheus-stack -n monitoring --values monitoring/values.yaml</pre><p>The Prometheus stack operator installation will be called ‘prom’ in this case. Feel free to name it whatever you want.</p><p>Note that I am running the command from within this git repository. Thus, the ‘values.yaml‘ file is hosted within a ‘monitoring‘ repository. Just make sure that you specify the right path to your values.yaml file.</p><p>The output in our terminal should look similar to the following screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*xXpUTXEZyLu3I6Hq.png" /></figure><p>Once the Helm chart has been deployed, we can open the Prometheus UI and the Grafana UI through the following commands:</p><p><strong>Prometheus</strong>:</p><pre>kubectl port-forward service/prom-kube-prometheus-stack-prometheus -n monitoring 9090:9090</pre><p><strong>Grafana</strong>:</p><pre>kubectl port-forward service/prom-grafana -n monitoring 3000:80</pre><p>In most cases, you will need the log-in credentials for Grafana; by default, those are going to be:</p><ul><li>Username: admin</li><li>Password: prom-operator</li></ul><p>However, you can also look at the secret that got deployed through the Prometheus Operator Helm Chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*Y5CYpOAohI9fggPl.png" /></figure><p>Next, we want to deploy Loki within our cluster. Loki is responsible for gathering logs from our application. In short, Loki is responsible for gathering and managing logs.</p><p>First, add the Grafana Helm Charts to your Helm cli:</p><pre>helm repo add grafana https://grafana.github.io/helm-charts</pre><pre>helm repo update</pre><p>Next, we can deploy the Promtail and Loki in our cluster. Promtail will require a little bit of custom set-up. Thus, we are going to create a new values file that will host our Promtail configuration. Let’s call it promtail-values.yaml with the following specification:</p><pre>config:</pre><pre>lokiAddress: &quot;http://loki-loki-distributed-gateway/loki/api/v1/push&quot;</pre><p>Next, deploy promtail and loki:</p><pre>helm upgrade --install promtail grafana/promtail -f monitoring/promtail-values.yaml -n monitoring</pre><pre>helm upgrade --install loki grafana/loki-distributed -n monitoring</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/0*DuQ8OOzr2sVUINP7.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/0*wMxkhHCGXHopMSqm.png" /></figure><p>Once the resources are up in the cluster, port-forward Grafana and open the Grafana data-sources. You should see them added:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V8aq_OHB8_hNFwVo.png" /></figure><h3>The Komodor Agent</h3><p>Next, we want to install the Komodor Agent into our cluster. While our monitoring stack will help us to track the behaviour of our workloads, Komodor will track changes to those workloads. The combination of both tools will help us, later on, to debug our deployments effectively.</p><pre>helm repo add komodorio https://helm-charts.komodor.io</pre><pre>helm repo update</pre><pre>helm upgrade --install k8s-watcher komodorio/k8s-watcher --set apiKey=YOUR_API_KEY_HERE --set watcher.clusterName=CLUSTER_NAME --set watcher.allowReadingPodLogs=true --set watcher.enableAgentTaskExecution=true --wait --timeout=90s</pre><p>You will be able to find your apiKey in the Komodor UI within the integration section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/0*I_r_Wetx_15SmgW_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/0*CKTJbLpDHhuECYDy.png" /></figure><p>Once our Komodor agent is running inside our cluster, we will be able to see all of our services in the Komodor Dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u0r68cN8Un7AMoZT.png" /></figure><p>From the Integrations section, we will now set-up our Komodor-Grafana Integration. The steps are provided in the UI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xwvORX-taUAE38P_" /></figure><h3>A Demo Application</h3><p>The example application is a simple ping-pong-app, one application pings the other and receives “pong” as a reply.</p><p>We want our application to live in a separate namespace. This will make it easier in the long term to separate our workloads and manage our deployments properly.</p><p>Create a new namespace:</p><pre>kubectl create ns demo</pre><p>Within the namespace, we are going to deploy three resources:</p><ol><li>A deployment.yaml manifest</li><li>A service.yaml manifest</li><li>A servicemonitor.yaml manifest</li></ol><p>The servicemonitor is responsible to tell our Prometheus deployment that there is a new application in town that has to be monitored.</p><p>Let’s deploy all resources to our cluster:</p><pre>kubectl apply -f ./application -n demo</pre><p>Now you can port forward our application:</p><pre>kubectl port-forward service/app -n demo 8080:8080</pre><p>It will not be very exciting but we have to make sure that our application has a metrics endpoint which Prometheus can monitor and through the UI we can already see our metrics:</p><p><a href="http://localhost:8080/metrics">http://localhost:8080/metrics</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/0*lCDHSlIkrjqlzgfJ" /></figure><p>Additionally, if you open your Prometheus dashboard, you should now see the new service within targets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eJErfpoowoSzQI_d" /></figure><p>Lastly, we have to deploy the pinger application to the same namespace. The pinger application will ping our pong application.</p><p>Run the following command to deploy the pinger:</p><pre>kubectl apply -f ./pinger -n demo</pre><p>If you open our application on localhost: <a href="http://localhost:8080/ping">http://localhost:8080/ping</a>, you will see a pong response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/0*jHCHy4wen0oxzILF" /></figure><p>Note: Please ignore the trace ID. This example has been taken from another demo that uses Tempo for tracing. We will look at using Tempo in one of my next demos.</p><h3>Let’s check our deployment in Grafana and Komodor</h3><p>The deployment of our ping-pong application stack should now be visible both in Grafana and in Komodor.</p><h3>Grafana</h3><p>For now, we don’t have a specific Dashboard for our application in Grafana. However, we can run a query in the explore section of the UI.</p><p>To calculate the average request duration during the last 5 minutes from a histogram or summary called http_request_duration_seconds, use the following expression:</p><pre>rate(http_request_duration_seconds_sum[5m])</pre><pre>/</pre><pre>rate(http_request_duration_seconds_count[5m])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gCh-_MGkMfSl6uXt" /></figure><p>Feel free to play around with the queries.</p><h3>Komodor</h3><p>Within ’Services’, we can see our app and the pinger application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/0*aUbq970mhtc7Q3Aq" /></figure><p>Taking a look at ’Events’ we can see all the updates that happened to our deployment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F7H9Rl0xVUPrWu9W" /></figure><p>Furthermore, another amazing debugging feature on Komodor is live logs from our deployment.</p><p>For this, we are going to click on the Health change of our pinger app. We can then see the YAML manifest that was used to deploy the pinger, additional events recorded in the cluster, as well as the live logs from the pod:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T7zLwEfZ-sw2XY-f" /></figure><p>Note that the errors likely come from not having Tempo set up and connected. It’s ok, we will fix it in another tutorial.</p><h3>Upps, something goes wrong</h3><p>We are now going to deploy a new version of our application. For the purpose of this tutorial, we are going to name it slow.</p><pre>kubectl -n demo set image deployment/app app=anaisurlichs/ping-pong:slow</pre><p>Once the image has been updated, we can see the latency of our application increase in the Grafana Dashboard (based on our previous query):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tVDJ1iLnQQXWTSEv" /></figure><p>Now imagine that you have alerts set up in Grafana that tell you whenever your application takes a long time to reply to requests. You don’t have more information beyond the alerts. Where do you start to debug your application?</p><p>With Komodor installed, this is pretty straightforward. Once we know from the alerts or our Grafana Dashboard when i.e. at what time our application became slow, we can head over to the Komodor Dashboard and see what changed with our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*44HEowR6XM1i3ozf" /></figure><p>As we can see, a new deployment was rolled out of our application.</p><p>This has likely been the cause for our alert/the high latency that we experienced from our application.</p><p>We now have a reason to look at the latest deployment and correct anything that might have caused the high latency.</p><p>Lastly, we are rolling out a new deployment:</p><pre>kubectl -n demo set image deployment/app app=anaisurlichs/ping-pong:best</pre><p>Now we can see that the latency of our application has recovered.</p><h3>What’s Next?</h3><p>In this blog post, we saw how we can set up our entire monitoring stack with the Prometheus Stack Operator Helm Chart. This included Prometheus and Grafana. To make our stack complete, we then deployed Loki with Promtail and the Komodor Agent. With every tool, we showcased how you can access its UI and get started using it. Lastly, we gave a demo example to show how you would use both your monitoring tools and Komodor to debug your deployment.</p><p>For more information, have a look at the resources provided by Komodor. They have great <a href="https://komodor.com/blog/">content on their blog</a> and comprehensive, on-demand webinars.</p><p>I hope to see you in my next tutorials!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0d600cd9a2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparison: Code Analysis Tools]]></title>
            <link>https://medium.com/containers-101/comparison-code-analysis-tools-625679b3871e?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/625679b3871e</guid>
            <category><![CDATA[codacy]]></category>
            <category><![CDATA[codecov]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[coveralls]]></category>
            <category><![CDATA[code-coverage]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Tue, 07 Dec 2021 10:02:39 GMT</pubDate>
            <atom:updated>2021-12-07T10:02:39.847Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ENfiuLaMmVzxaSUwfPW5g.png" /></figure><p>Code analysis tools are essential to gain an overview and understanding of the quality of your code. This post is going to cover the following</p><ol><li><a href="https://about.codecov.io/">Codecov</a>;</li><li><a href="https://coveralls.io/">Coveralls</a>;</li><li>And <a href="https://www.codacy.com/">Codacy</a>;</li></ol><p>While these tools target similar use cases, they differ in their implementation, ease of use, and documentation just to name a few.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*s2YQOWd3GXpaXZ0s.png" /></figure><p>This post provides an overview of each tool as well as a detailed comparison to help analyse and decide which tool is best suited for your needs.</p><h3>Overview</h3><p>Code analysis tools make it possible to access, group, and merge analysis reports of your application. Test coverage reports used in combination with code analysis tools provide comprehensive insights on the quality of your code.</p><p>This allows developers to know their code quality today and improve it tomorrow. Specifically, to</p><ul><li>Improve poorly written code;</li><li>Develop robust and secure applications;</li><li>Receive insights into the code quality over time;</li><li>Ensure test coverage is done throughout the codebase.</li></ul><p>In the best case, you would want to have all the insights on your code quality in one place. This is made possible by Codacy, Codecov, and Coveralls.</p><p>The next sections will compare distinct aspects of each tool with its competitors. We tried all 3 tools with our own project in order to gain a better understanding of how they work. Here is each blog post if you want to see what we did:</p><ul><li><a href="https://codefresh.io/howtos/code-coverage-codecov/">Codecov</a></li><li><a href="https://codefresh.io/howtos/code-coverage-reports-using-coveralls-codefresh/">Coveralls</a></li><li><a href="https://codefresh.io/howtos/codacy-coverage-reports/">Codacy</a></li></ul><h3>Features</h3><p>Now that we discovered that all three tools have the same goals in mind, let’s take a look at the features each tool pursues and the ways they differ.</p><p><strong>Each tool has been evaluated based on the following criteria</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*cgxCNvmUfbBq8zM-9Ayr7w.png" /><figcaption>Comparison Table</figcaption></figure><h3>Pricing</h3><p>Both Codacy and Codecov provide a free version, a pro-version and an on-premises version. In the case of Codecov, all pricing options are <a href="https://about.codecov.io/pricing/">detailed on their website.</a> In comparison, <a href="https://www.codacy.com/pricing">Codacy does not clearly state</a> the service provided with the free version. Additionally, both platforms charge per user, who receives access to an organization’s repository.</p><p>Coveralls, on the other hand, has more <a href="https://coveralls.io/pricing">segmented pricing options</a> with 5 different tiers. Additionally, it provides free analysis for open source. The remaining options are priced depending on the number of repositories that receive coverage reports rather than the number of users, who need access to the platform.</p><p>Given the information provided by each tool, we would recommend startups and open-source projects to go with Coveralls. While they currently do not provide extensive support to projects, they clearly state their belief in the open-source ethos and provide a flexible pricing model. Additionally, paying Coveralls per repository provides more predictable pricing. Depending on the size of your team and the number of repositories that have to be covered, Codecov will provide the best option for its price. However, if your company would like to receive additional features, it might be worth looking into the enterprise and on-premises solutions provided by Codecov and Codacy since both provide a few more features than Codecov.</p><h3>Reports and Analysis</h3><p>All three platforms provide a comprehensive dashboard through which code analysis reports can be accessed. This section will look at the features of each platform before providing a comparison. Note that we uploaded to each platform the same coverage report.</p><p>The coverage reports uploaded to each platform were based on a<a href="https://github.com/codefresh-contrib/coveralls-sample-app"> Typescript application</a>. Thus, reports had to be in either of the following formats: json, xml, or txt.</p><p>Both <a href="https://docs.codecov.io/docs/supported-languages">Codecov</a> and <a href="https://docs.coveralls.io/">Coveralls</a> suggest different testing and coverage report frameworks depending on the language used throughout a comprehensive list of examples. In comparison, Codacy provides <a href="https://docs.codacy.com/coverage-reporter/generating-coverage-reports/">a list of suggestions</a> that are not directly managed by Codacy. This makes it a bit more difficult to understand the potential and implementation of Codacy. Once we have uploaded our coverage report, we can view the information in the respective Dashboards.</p><h3>Codecov</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/0*wjO59M_p7CVSy3No.png" /></figure><p>The Codecov Dashboard is divided into several sections with a top menu bar. Each coverage report is classified in either of the following categories:</p><ul><li><strong>hit</strong> indicates that the source code was executed by the test suite.</li><li><strong>partial</strong> indicates that the source code was not fully executed by the test suite; there are remaining branches that were not executed.</li><li><strong>miss</strong> indicates that the source code was not executed by the test suite.</li></ul><p>This is visible in the files section of the Dashboard in the form of a street-light system.</p><h3>Coveralls</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/0*If665AaZS8ippBKS.png" /></figure><p>Coveralls follows a unique style throughout its platform. Similar to Codecov, Coveralls uses the percentage of the project covered by tests to analyze its code quality. Furthermore, with every new code coverage upload, Coveralls makes a separate entry into the recent builds section of the Dashboard. This entry includes the coverage percentage of the repository. While a graph for enhanced visualisation of code coverage improvements would be nice, it is not necessary to understand the coverage change over time.</p><h3>Codacy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*sbd8xSrUdbyeYq7G.png" /></figure><p>Similar to Codecov, Codacy focuses on enhancing its code analysis by connecting coverage reports with the information recorded on your git repository. This includes issues, pull requests and commits. From the main Dashboard, users can access specific information on the repository, such as file coverage. However, Codacy does not provide you with an option to view coverage reports directly. The pro version allows users to set-up security alerts, which is a feature that is unique to Codacy.</p><p>Separately, Codacy provides additional tools such as user management, separate configuration for file support, and setting quality standards.</p><h4>Comparison</h4><ul><li>Coveralls was the most intuitive platform of the three. However, this can be considered a positive side-effect of Coveralls focusing on the core features needed to create curated coverage reports rather than providing too many options that might confuse users.</li><li>In contrast, both Codecov and Codacy place more focus on the visualisation of the coverage reports that enhance the Dashboard.</li><li>An additional feature worth highlighting is the option to compare branches directly within the Codecov UI.</li><li>In the case of Codacy, the complex UI used to accommodate all features was a problem. The Codacy UI has two settings taps with similar features. When setting up the integration, it was not clear which API token should be used. More on this in the integration section.</li><li>Overall, there is not much to set-up or to customise within the UI, which results in a similar workflow while using each tool.</li></ul><h3>Historical Trends</h3><p>Historical Trends are necessary to reason between events, changes done to the code base and the results of the code coverage. Depending on the way historical trends are displayed, it becomes easier for developers to identify good practices that led to higher code quality.</p><p>All platforms provide historical trends. While Codacy provides the best visualisation of reports over time as an average, it makes it difficult to access coverage reports directly from within the tool. Looking at Codecov and Coveralls, also the simplified Dashboards makes it possible to reason about changes in code coverage within respective files and repositories.</p><p>Summarising, the information provided by Codacy is better when looked at high-level but does not provide an advantage when users want to analyse specific files.</p><h3>Code Analysis</h3><p>Using a code coverage solution makes it possible for users to access additional information on the quality of their code. The following screenshots showcase the analysis interface of the file that we ran tests on. It is worth highlighting that Codacy analyses the code quality of all files within the git repository by default. Resulting, also files that are not part of the code coverage report are automatically analysed.</p><p><strong>Codecov</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*FbHBWOrL-9tyd6Yp.png" /></figure><p><strong>Coveralls</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*DvAaalnb3MHLgfEZ.png" /></figure><p><strong>Codacy</strong></p><p>Note that Codacy has some additional logic that did not allow us to access the js file created from the ts file. Thus, we used the ts file instead to analyse our code quality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*1q5-tzukEHmXWOkD.png" /></figure><p>In this category, Codacy clearly provided the most information on each line of code, highlighting the improvements that can be made. However, by doing so, the platform enforces specific practices onto your codebase. For instance, in the case of JavaScript, there is no need to provide semicolons but their tool will flag those as missing and downgrade the code quality. By not flagging distinct coding styles, Codacy could be used to enforce a coding style within the organisation.</p><h3>Documentation</h3><p>Your need for good documentation will vary, depending on the way you want to use the tools and access code coverage reports. Sadly, the documentation is often that part of a product that is least taken care of. Good documentation allows users to get started quickly, avoid ambiguity, and optimise the use of the platform over time.</p><p>When comparing the documentation by Codecov, Coveralls and Codacy, the following became apparent</p><ul><li>Codecov has the most comprehensive documentation since it covers every aspect of the product with great detail.</li><li>Coveralls’ documentation was the easiest to navigate given that it focuses on the essential operations that users would want to do.</li><li>Both Codecov and Coveralls provide a comprehensive list of examples that users can choose from depending on the programming language and framework used in their application. This was greatly missed within Codacy, which is further detailed in the next section.</li></ul><h3>Use and Ease of Implementation</h3><p>The use and ease of implementation is arguably the most important aspect of each platform. Depending on the tool that is added to your existing workflow, you do not want to change your entire processes to accommodate one tool. Thus, it is necessary for code coverage and analysis tools to understand at what point coverage reports are created in the development lifecycle. This will allow the tool to provide seamless integration into the testing and coverage process that a team has already established.</p><p>Using Codefresh to connect our code coverage reports to the respective tool makes it possible to automate the process of running tests, creating coverage reports, and uploading those to the code analysis tool. This section will detail our experience integrating each analysis tool within our Codefresh pipeline.</p><h3>Integrate with each tool</h3><p>The connection between the tool and your application is made through a repository token. Independent of the tool you are using, you will be provided with a repository token once you grant the platform access to a new git repository. The repository token is set as an environment variable either in your local installation or within your CI/CD platform.</p><p>In the case of Coveralls, it was necessary to install a node package and a script was added to the repository. The script can be modified to provide additional information on the application. Further details are provided in the <a href="https://codefresh.io/howtos/code-coverage-reports-using-coveralls-codefresh/">Coveralls specific blog post</a>.</p><p>Codecov merely required a specific set-up of the code coverage tool used.</p><p>Codacy was a bit special in this regard. Instead of installing a script or package within the application, users have to call a remote script. While it might seem more user friendly at the beginning, it has several disadvantages. Namely:</p><ul><li>The script has to be called every time that the code coverage report is pushed to the Codacy account. If the script changes, it might result no longer be compatible with the coverage reports used and fail to upload those.</li><li>In case of an error, users do not have insights on what has gone wrong. In our case, Codacy was unable to access the right file within the repository and as a result, did not display coverage resorts. However, the script behaved as if it ran successfully.</li></ul><h3>Pipeline Creation</h3><p>One heavily promoted feature within each code coverage tool is the possibility to integrate it directly within your existing CI/CD platform. To evaluate the use of each tool, we set-up a CI/CD pipeline for each tool within Codefresh. The process was highly similar across tools and resulted in the following pipeline for Codecov:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*J0h1XPpUSiTSV6r2.png" /></figure><p>Note that we have access to the live logging through the ‘Output’ section in the Codefresh UI.</p><p>This section specifically details the use of integrating either of the code coverage tools into Codefresh pipelines. The first steps of the Codecov pipeline are provided as an example. In Codefresh, each step is its own Docker image. At the beginning of standard pipelines, the git repository is cloned, a container image created and pushed to the user’s container registry. These steps were the same for each tool.</p><pre>version: &quot;1.0&quot;<br># Stages can help you organize your steps in stages<br>stages:<br>  - &quot;clone&quot;<br>  - &quot;build&quot;<br>  - &quot;test&quot;</pre><pre>steps:<br>  clone:<br>    title: &quot;Cloning repository&quot;<br>    type: &quot;git-clone&quot;<br>    repo: &quot;codefresh-contrib/codecov-sample-app&quot;<br>    # CF_BRANCH value is auto set when pipeline is triggered<br>    # Learn more at codefresh.io/docs/docs/codefresh-yaml/variables/<br>    revision: &quot;${{CF_BRANCH}}&quot;<br>    git: &quot;github&quot;<br>    stage: &quot;clone&quot;</pre><pre>  build:<br>    title: &quot;Building Docker image&quot;<br>    type: &quot;build&quot;<br>    image_name: &quot;codefresh-contrib/codecov-sample-app&quot;<br>    working_directory: &quot;${{clone}}&quot;<br>    tag: &quot;${{CF_BRANCH_TAG_NORMALIZED}}&quot;<br>    dockerfile: &quot;Dockerfile&quot;<br>    stage: &quot;build&quot;</pre><p>Next, we had to run the tests, create coverage reports of our projects, and forward those to each platform. This is done in its own container image. For our application, we used the node image within each pipeline. The implementation for forwarding coverage reports between our Codefresh pipeline varied between Codecov, Coveralls, and Codacy.</p><pre>test:<br>    title: &quot;Running test&quot;<br>    type: &quot;freestyle&quot; # Run any command<br>    image: &quot;anaisurlichs/codecov-sample-app:master&quot; # The image in which command will be executed<br>    working_directory: &quot;${{clone}}&quot; # Running command where code cloned<br>    commands:<br>      - &quot;npm run test&quot;<br>    stage: &quot;test&quot;</pre><pre>upload:<br>    title: &quot;Pushing to Codecov&quot;<br>    type: &quot;freestyle&quot; # Run any command<br>    image: &quot;node:15.2&quot; # The image in which command will be executed<br>    working_directory: &quot;${{clone}}&quot; # Running command where code cloned<br>    commands:<br>      - &quot;ci_env=`curl -s https://codecov.io/env`&quot;<br>      - &quot;npm install codecov -g&quot;<br>      - &quot;codecov -t ${{CODECOV_TOKEN}} -f ./coverage/clover.xml&quot;<br>    stage: &quot;test&quot;</pre><p>Note that it would have been best if each tool would provide their own container image that can be used within CI/CD pipelines instead of using the generic node image. This would have reduced the need for a custom workaround and makes it possible to optimize the process.</p><h3>Let’s Recap</h3><p>This post provided an overview and comparison of three different code analysis tools. Namely, Codecov, Coveralls and Codacy. All three tools have the same goal of accessing code coverage reports and generating curated insights over time.</p><p>When explored in more detail it becomes visible that all tools have a different focus on their implementation of features. This results in a tradeoff between access to features and ease of use. While Codacy is the most advanced tool of the three, it was more difficult to set-up and to navigate its UI. In contrast, Coveralls focuses on the minimum functionality needed to access and analyse code coverage reports. Comparing the free version of each tool, there is no significant difference between tools.</p><p>If you are interested in each tool specifically, we highly recommend you to have a look at our previous blog posts on:</p><ul><li><a href="https://codefresh.io/howtos/code-coverage-codecov/">Codecov</a></li><li><a href="https://codefresh.io/howtos/code-coverage-reports-using-coveralls-codefresh/">Coveralls</a></li><li>And <a href="https://codefresh.io/howtos/codacy-coverage-reports/">Codacy</a></li></ul><p>Each tool can be automated through Codefresh; simply by creating a pipeline for your project that integrates with the respective code coverage tool.</p><p><a href="https://codefresh.io/codefresh-signup/?utm_source=Blog&amp;utm_medium=Post&amp;utm_campaign=codeanalysiscomparison">Create Your Free Account today and try it out!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=625679b3871e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/containers-101/comparison-code-analysis-tools-625679b3871e">Comparison: Code Analysis Tools</a> was originally published in <a href="https://medium.com/containers-101">Container Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Policy Rules MADE EASY]]></title>
            <link>https://anaisurl.medium.com/custom-policy-rules-made-easy-8c6b3091d383?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c6b3091d383</guid>
            <category><![CDATA[policy]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Thu, 25 Nov 2021 16:02:51 GMT</pubDate>
            <atom:updated>2021-11-25T16:02:51.424Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33N6WehXMVmBJXBXaSP61A.png" /></figure><p>If you are using Kubernetes a lot, you likely have used Custom Resources Definitions in Kubernetes. The power of Kubernetes lies in the Kube API, which allows cloud native applications to extend Kubernetes resources with custom resources. This allows you to potentially create anything as a Kubernetes resource.</p><p>While this is a pretty dope feature, it also comes with a few downsides. For instance, anything that you customize will not have the same community support as a tool that you use “out of the box”.</p><p>You want to prevent that people who have access to your Kubernetes cluster e.g. team members are able to install malicious resources but follow best practices and potentially, are constraint in the type of resources that they are able to create on a Kubernetes cluster. Best practices can be enforced through policies. However, custom resources don’t have out-of-the-box policies that you can implement.</p><p>In this blog post, I am going to introduce you to Datree custom rules. Datree makes it possible for users to write custom rules to check your Kubernetes custom resource definitions for misconfigurations.</p><p>If you prefer the video tutorial, you can find it linked below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7g8L_30_DSU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7g8L_30_DSU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7g8L_30_DSU%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/2db602ba54065c5ef8123370a331c572/href">https://medium.com/media/2db602ba54065c5ef8123370a331c572/href</a></iframe><p>For this, we are going to write Policies as Code. If you are completely new to Datree and/or Policies as Code, I highly suggest you have a look at my previous video on Datree that showcases how you can get started with Policies as Code.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMpdhrabnpYs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMpdhrabnpYs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMpdhrabnpYs%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/f119ade961ebfec1d1928623f5102d29/href">https://medium.com/media/f119ade961ebfec1d1928623f5102d29/href</a></iframe><h3>Prerequisites</h3><p>To follow this tutorial, the one thing that you must have enabled are Policies as Code from the Datree Settings Menu. Once you have enabled it, you will be able to install the policy resources. To enable Policies follow these steps:</p><p><strong>Access Account</strong></p><p>If you do not have Datree installed yet, go ahead and install the CLI by running the following command in your terminal:</p><p>curl <a href="https://get.datree.io/">https://get.datree.io</a> | /bin/bash</p><p>For different installation instructions, please have a look at the <a href="https://hub.datree.io/">Datree documentation.</a></p><p>There are two ways in which you can access the Dashboard. The first one is that you run the example test command from the documentation:</p><pre>datree test ~/.datree/k8s-demo.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2-fs6rlnnNhnp82P.png" /></figure><p>Alternatively, you can go to app.datree.io and you will be able to access your Dashboard.</p><p><strong>Enable Policy as Code</strong></p><p>To enable Policy as Code, head over to <strong>Your Account</strong> (top left) &gt; <strong>Settings;</strong> next:</p><ol><li>Enable Policy as Code</li><li>Download the policies.yaml file</li></ol><p>This file will contain all the default policies. You can also see an example in the documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*5ZrsvKSE7-LTe8MG.png" /></figure><h3>Custom Policies</h3><p>The <a href="https://hub.datree.io/custom-rules-overview">Datree documentation</a> provides a great overview of how to write custom rules. You can write the custom rules either in JSON or YAML format. In my case, I am going to go with the YAML format since this is what I am already used to.</p><p>We are going to start off with our policies.yaml file from the previous example. Currently, we are not making use of any custom rules.</p><pre>apiVersion: v1<br>policies:<br>  - name: Staging<br>    isDefault: true<br>    rules:<br>      - identifier: CONTAINERS_MISSING_IMAGE_VALUE_VERSION<br>        messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant “version surprises” in the future<br>      - identifier: CRONJOB_INVALID_SCHEDULE_VALUE<br>        messageOnFailure: &#39;Incorrect value for key `schedule` - the (cron) schedule expressions is not valid and therefor, will not work as expected&#39;<br>      - identifier: WORKLOAD_INVALID_LABELS_VALUE<br>        messageOnFailure: Incorrect value for key(s) under `labels` - the vales syntax is not valid so it will not be accepted by the Kuberenetes engine<br>      - identifier: WORKLOAD_INCORRECT_RESTARTPOLICY_VALUE_ALWAYS<br>        messageOnFailure: Incorrect value for key `restartPolicy` - any other value than `Always` is not supported by this resource<br>      - identifier: HPA_MISSING_MAXREPLICAS_KEY<br>        messageOnFailure: Missing property object `maxReplicas` - the value should be within the accepted boundaries recommended by the organization<br>      - identifier: WORKLOAD_INCORRECT_NAMESPACE_VALUE_DEFAULT<br>        messageOnFailure: Incorrect value for key `namespace` - use an explicit namespace instead of the default one (`default`)<br>      - identifier: DEPLOYMENT_INCORRECT_REPLICAS_VALUE<br>        messageOnFailure: Incorrect value for key `replicas` - don&#39;t relay on a single pod to do all of the work. Running 2 or more replicas will increase the availability of the service<br>      - identifier: K8S_DEPRECATED_APIVERSION_1.16<br>        messageOnFailure: Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (&gt;=1.16)<br>      - identifier: K8S_DEPRECATED_APIVERSION_1.17<br>        messageOnFailure: Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (&gt;=1.17)<br>      - identifier: CONTAINERS_INCORRECT_PRIVILEGED_VALUE_TRUE<br>        messageOnFailure: Incorrect value for key `privileged` - this mode will allow the container the same access as processes running on the host<br>      - identifier: CRONJOB_MISSING_CONCURRENCYPOLICY_KEY<br>        messageOnFailure: Missing property object `concurrencyPolicy` - the behavior will be more deterministic if jobs won&#39;t run concurrently<br>      - identifier: HPA_MISSING_MINREPLICAS_KEY<br>        messageOnFailure: &#39;Missing property object `minReplicas` - the value should be within 3 to 5 pods. Please contact @AnaisUrlichs for further information. &#39;<br>      - identifier: SERVICE_INCORRECT_TYPE_VALUE_NODEPORT<br>        messageOnFailure: &#39;Incorrect value for key `type` - `NodePort` will open a port on all nodes where it can be reached by the network external to the cluster. Please use ClusterIP instead. Contact @AnaisUrlichs for further information. &#39;<br>  - name: Prod<br>    rules:<br>      - identifier: CONTAINERS_MISSING_IMAGE_VALUE_VERSION<br>        messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant “version surprises” in the future<br>      - identifier: K8S_INCORRECT_KIND_VALUE_POD<br>        messageOnFailure: Incorrect value for key `kind` - raw pod won&#39;t be rescheduled in the event of a node failure<br>      - identifier: CONTAINERS_MISSING_MEMORY_REQUEST_KEY<br>        messageOnFailure: Missing property object `requests.memory` - value should be within the accepted boundaries recommended by the organization.<br>      - identifier: CONTAINERS_MISSING_CPU_REQUEST_KEY<br>        messageOnFailure: Missing property object `requests.cpu` - value should be within the accepted boundaries recommended by the organization<br>      - identifier: CONTAINERS_MISSING_MEMORY_LIMIT_KEY<br>        messageOnFailure: Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization<br>      - identifier: CONTAINERS_MISSING_CPU_LIMIT_KEY<br>        messageOnFailure: Missing property object `limits.cpu` - value should be within the accepted boundaries recommended by the organization</pre><p>As you can see in the file, we currently specify the rules for two different environments “Prod” and “Staging”. However, the existing rules provided by Datree will not cover our Custom Resource Definitions. Thus, once we create custom resources, we will want to add custom rules.</p><h3>Example</h3><p>Next, we will need an example of custom resources based on which we can then go ahead and create our custom rule. You can use any Kubernetes custom resource definition for this.</p><p>I am going to create custom policies for my cluster.yaml resources that I am giving Crossplane to create a Kubernetes cluster for me.</p><p>If you are completely new to Crossplane, have a look at my previous video.</p><p>Crossplane allows us to specify what kind of resources we can create on a cloud provider through custom resources.</p><p>My cluster.yaml file looks something along these lines:</p><pre>kind: CivoKubernetes<br>apiVersion: cluster.civo.crossplane.io/v1alpha1<br>metadata: <br>  name: second-crossplane<br>spec:<br>  name: second-crossplane<br>  instances: 5<br>  size: g3.k3s.large<br>  applications: <br>    - &quot;prometheus-operator&quot;<br>    - &quot;istio:Istio v1.10.1&quot;<br>  connectionDetails:<br>    connectionSecretNamePrefix: &quot;cluster-details&quot;<br>    connectionSecretNamespace: &quot;default&quot;<br>  providerConfigRef:<br>    name: civo-provider</pre><p>This file is specifically written to create a Civo Kubernetes resources through the Civo Crossplane provider. To learn more about both, have a look at the following blog post: <a href="https://www.civo.com/learn/civo-crossplane-provider">https://www.civo.com/learn/civo-crossplane-provider</a></p><p>Next, I want to create several custom rules. These rules will be used to check whether the cluster.yaml file is configured correctly.</p><pre>customRules:<br>  - identifier: CUSTOM_CLUSTER_SIZE<br>    name: Ensure correct cluster size is used [CUSTOM RULE]<br>    defaultMessageOnFailure: Use only small or medium clusters <br>    schema:<br>      properties:<br>        spec:<br>          properties:<br>            size:<br>              enum:<br>                - g3.k3s.small<br>                - g3.k3s.medium<br>              required:<br>                - size<br>  - identifier: CUSTOM_CLUSTER_INSTANCES<br>    name: Ensure only a limited number of instances are used [CUSTOM RULE]<br>    defaultMessageOnFailure: Use only 2,3,4 instance sizes<br>    schema:<br>      properties:<br>        spec:<br>          properties:<br>            instances:<br>              type: number<br>              enum:<br>                - 2<br>                - 3<br>                - 4<br>  - identifier: CUSTOM_WORKLOAD_INCORRECT_ENVIRONMENT_LABELS<br>    name: Ensure correct environment labels are used [CUSTOM RULE]<br>    defaultMessageOnFailure: Use only approved environment labels (`prod`, `staging` and `test`)<br>    schema:<br>      properties:<br>        metadata:<br>          properties:<br>            labels:<br>              properties:<br>                environment:<br>                  enum:<br>                    - prod<br>                    - staging<br>                    - test<br>              required:<br>              - environment<br>          required:<br>          - labels</pre><p>Again, please have a look at the <a href="https://hub.datree.io/custom-rules-overview">Datree documentation</a> to see how you can set up these custom rules.</p><p>Next, we have to reference the custom rules in our policies.yaml file. Thus, we are going to create a new section within “policies” that will reference our custom rules:</p><pre>- name: Crossplane<br>    rules:<br>      - identifier: CUSTOM_CLUSTER_SIZE<br>        messageOnFailure: Ensure correct cluster size is used [CUSTOM RULE]<br>      - identifier: CUSTOM_CLUSTER_INSTANCES<br>        messageOnFailure: Ensure only a limited number of instances are used [CUSTOM RULE]<br>      - identifier: CUSTOM_WORKLOAD_INCORRECT_ENVIRONMENT_LABELS<br>        messageOnFailure: Please choose either staging, test, or prod environments</pre><p>My entire policies.yaml file will now look as follows:</p><pre>apiVersion: v1<br>policies:<br>  - name: Staging<br>    isDefault: true<br>    rules:<br>      - identifier: CONTAINERS_MISSING_IMAGE_VALUE_VERSION<br>        messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant “version surprises” in the future<br>      - identifier: CRONJOB_INVALID_SCHEDULE_VALUE<br>        messageOnFailure: &#39;Incorrect value for key `schedule` - the (cron) schedule expressions is not valid and therefor, will not work as expected&#39;<br>      - identifier: WORKLOAD_INVALID_LABELS_VALUE<br>        messageOnFailure: Incorrect value for key(s) under `labels` - the vales syntax is not valid so it will not be accepted by the Kuberenetes engine<br>      - identifier: WORKLOAD_INCORRECT_RESTARTPOLICY_VALUE_ALWAYS<br>        messageOnFailure: Incorrect value for key `restartPolicy` - any other value than `Always` is not supported by this resource<br>      - identifier: HPA_MISSING_MAXREPLICAS_KEY<br>        messageOnFailure: Missing property object `maxReplicas` - the value should be within the accepted boundaries recommended by the organization<br>      - identifier: WORKLOAD_INCORRECT_NAMESPACE_VALUE_DEFAULT<br>        messageOnFailure: Incorrect value for key `namespace` - use an explicit namespace instead of the default one (`default`)<br>      - identifier: DEPLOYMENT_INCORRECT_REPLICAS_VALUE<br>        messageOnFailure: Incorrect value for key `replicas` - don&#39;t relay on a single pod to do all of the work. Running 2 or more replicas will increase the availability of the service<br>      - identifier: K8S_DEPRECATED_APIVERSION_1.16<br>        messageOnFailure: Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (&gt;=1.16)<br>      - identifier: K8S_DEPRECATED_APIVERSION_1.17<br>        messageOnFailure: Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (&gt;=1.17)<br>      - identifier: CONTAINERS_INCORRECT_PRIVILEGED_VALUE_TRUE<br>        messageOnFailure: Incorrect value for key `privileged` - this mode will allow the container the same access as processes running on the host<br>      - identifier: CRONJOB_MISSING_CONCURRENCYPOLICY_KEY<br>        messageOnFailure: Missing property object `concurrencyPolicy` - the behavior will be more deterministic if jobs won&#39;t run concurrently<br>      - identifier: HPA_MISSING_MINREPLICAS_KEY<br>        messageOnFailure: &#39;Missing property object `minReplicas` - the value should be within 3 to 5 pods. Please contact @AnaisUrlichs for further information. &#39;<br>      - identifier: SERVICE_INCORRECT_TYPE_VALUE_NODEPORT<br>        messageOnFailure: &#39;Incorrect value for key `type` - `NodePort` will open a port on all nodes where it can be reached by the network external to the cluster. Please use ClusterIP instead. Contact @AnaisUrlichs for further information. &#39;<br>  - name: Prod<br>    rules:<br>      - identifier: CONTAINERS_MISSING_IMAGE_VALUE_VERSION<br>        messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant “version surprises” in the future<br>      - identifier: K8S_INCORRECT_KIND_VALUE_POD<br>        messageOnFailure: Incorrect value for key `kind` - raw pod won&#39;t be rescheduled in the event of a node failure<br>      - identifier: CONTAINERS_MISSING_MEMORY_REQUEST_KEY<br>        messageOnFailure: Missing property object `requests.memory` - value should be within the accepted boundaries recommended by the organization.<br>      - identifier: CONTAINERS_MISSING_CPU_REQUEST_KEY<br>        messageOnFailure: Missing property object `requests.cpu` - value should be within the accepted boundaries recommended by the organization<br>      - identifier: CONTAINERS_MISSING_MEMORY_LIMIT_KEY<br>        messageOnFailure: Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization<br>      - identifier: CONTAINERS_MISSING_CPU_LIMIT_KEY<br>        messageOnFailure: Missing property object `limits.cpu` - value should be within the accepted boundaries recommended by the organization<br>  - name: Crossplane<br>    rules:<br>      - identifier: CUSTOM_CLUSTER_SIZE<br>        messageOnFailure: Ensure correct cluster size is used [CUSTOM RULE]<br>      - identifier: CUSTOM_CLUSTER_INSTANCES<br>        messageOnFailure: Ensure only a limited number of instances are used [CUSTOM RULE]<br>      - identifier: CUSTOM_WORKLOAD_INCORRECT_ENVIRONMENT_LABELS<br>        messageOnFailure: Please choose either staging, test, or prod environments<br>customRules:<br>  - identifier: CUSTOM_CLUSTER_SIZE<br>    name: Ensure correct cluster size is used [CUSTOM RULE]<br>    defaultMessageOnFailure: Use only small or medium clusters <br>    schema:<br>      properties:<br>        spec:<br>          properties:<br>            size:<br>              enum:<br>                - g3.k3s.small<br>                - g3.k3s.medium<br>              required:<br>                - size<br>  - identifier: CUSTOM_CLUSTER_INSTANCES<br>    name: Ensure only a limited number of instances are used [CUSTOM RULE]<br>    defaultMessageOnFailure: Use only 2,3,4 instance sizes<br>    schema:<br>      properties:<br>        spec:<br>          properties:<br>            instances:<br>              type: number<br>              enum:<br>                - 2<br>                - 3<br>                - 4<br>  - identifier: CUSTOM_WORKLOAD_INCORRECT_ENVIRONMENT_LABELS<br>    name: Ensure correct environment labels are used [CUSTOM RULE]<br>    defaultMessageOnFailure: Use only approved environment labels (`prod`, `staging` and `test`)<br>    schema:<br>      properties:<br>        metadata:<br>          properties:<br>            labels:<br>              properties:<br>                environment:<br>                  enum:<br>                    - prod<br>                    - staging<br>                    - test<br>              required:<br>              - environment<br>          required:<br>          - labels</pre><p>As you can see, I am now referencing:</p><ol><li>My environment-specific rules that make use of the existing rules provided by Datree</li><li>A new environment, called “Crossplane”</li><li>My custom rules are defined at the end of the file, at the same level of “apiVersion”</li></ol><p>Next, I want to publish my custom rules to Datree to make use of my custom rules:</p><p>Once I publish my policies, I will see my new “Corssplane” environment appear in the Datree UI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lFM6ShhAg4g1d-xO.png" /></figure><p>Note: You can access the Datree UI by running “datree test”. This will provide you with a link to your UI.</p><p>Scrolling down, through my policies, I can then see that my custom rules have been activated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W621qXt8aQUFObzL.png" /></figure><h3>Test your Custom Resource Definitions</h3><p>Next, I am going to test my cluster.yaml file to see whether or not my new Crossplane-specific policies pass:</p><p>Note that we require the flag ` — ignore-missing-schema` since we are using a custom schema for Crossplane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/0*BYV3iIZtqm0sNuxr.PNG" /></figure><p>As you can see, two of our policies are currently not passing. Thus, we have to update our Custom Resource Definition for our cluster. The updated version will be the following:</p><p>Once we test the cluster.yaml file again, we can now see that all of our custom rules for Crossplane are passing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IWvADA9pvwAp6g59.png" /></figure><h3>What’s next?</h3><p>In this blog post, I showed you</p><ul><li>The magic of Custom Resource Definitions</li><li>Why you want to consider using custom policies</li><li>How you can get started with custom rules in Datree</li></ul><p>If you would like to see more on optimising your deployments, custom rules, or even more security-related topics, please let me know.</p><p>Lastly, make sure to give <a href="https://github.com/datreeio/datree">Datree a GH star</a> and to share this blog post to make sure that others will see it too.</p><p>Until next time 👋🏼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c6b3091d383" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GitOps best practices — Policy as Code on Datree]]></title>
            <link>https://anaisurl.medium.com/gitops-best-practices-policy-as-code-on-datree-89753a99c6cd?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/89753a99c6cd</guid>
            <category><![CDATA[policy-as-code]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[kubernetes-tutorial]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Tue, 19 Oct 2021 08:07:44 GMT</pubDate>
            <atom:updated>2021-10-19T08:07:44.212Z</atom:updated>
            <content:encoded><![CDATA[<h3>GitOps best practices — Policy as Code on Datree</h3><p>How do you know your YAML manifests are configured correctly? How do you know you are following the best practices when deploying your microservices to your Kubernetes cluster? Usually, this is a learning process that requires writing lots, and lots of YAML — deploying those manifests — and experiencing what works, what does not, and where are you encountering errors.</p><p>However, there are several tools that can make it easier for you to write thorough and secure Kubernetes Manifests. One of those tools is <a href="https://www.datree.io/">Datree</a>. Datree helps us to prevent Kubernetes misconfigurations from reaching production. This is done by comparing your Kubernetes manifests with the best practices from the Kubernetes release and the experience across countless organisations.</p><p>If you would like to learn more about getting started with Datree, have a look at the following YouTube tutorial and the <a href="https://hub.datree.io/">documentation</a>. Datree makes it extremely easy to get started in just two commands.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMpdhrabnpYs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMpdhrabnpYs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMpdhrabnpYs%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/f119ade961ebfec1d1928623f5102d29/href">https://medium.com/media/f119ade961ebfec1d1928623f5102d29/href</a></iframe><p>In the video linked above, I showcased how you can define your Kubernetes Policies within the Datree UI Dashboard. This method is pretty straightforward; you can enable and disable policies, set the description of policies and tag people’s GitHub account or add links for further information.</p><p>A lot of DevOps -related work is done in the Terminal. With methodologies such as Infrastructure as Code and GitOps gaining popularity, DevOps Engineers, Developers and administrators aim to define all resources as Code and track the versioning in Git.</p><p>Datree allows us to do exactly this — define our Policy as Code.</p><p>Resulting, instead of having to update all the policies within the UI, we can define our Kubernetes Policies in YAML and apply those to our Datree account.</p><p>You can view the video tutorial here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FxOppJthE1nA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DxOppJthE1nA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FxOppJthE1nA%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/ed04a02b6a0c808fc58fea8aa0806983/href">https://medium.com/media/ed04a02b6a0c808fc58fea8aa0806983/href</a></iframe><h3>How does that work?</h3><p>Upon using Datree, an account is created for you with a unique Account Token. You enable other team members to access the account by sharing the account token.</p><p>This makes it possible for Datree to manage all your account information centrally. Resulting, you can access the same information whether you are using Datree locally in your terminal or through a CI/CD platform, such as GitHub Actions.</p><p>The below diagram provides an overview:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CsKEM9LbWMoE9iNTlOV6CQ.png" /><figcaption>Datree Account Overview</figcaption></figure><h3>Policy as Code</h3><p>In this section, we are going to</p><ul><li>Access our Datree account &amp; download the default policy file</li><li>Modify the Policies for two different environments, staging and production</li><li>Apply our policy configuration</li><li>Test our policy configuration for both environments with the same YAML Manifests</li></ul><p><strong>Access Account</strong></p><p>If you do not have Datree installed yet, go ahead and install the CLI by running the following command in your terminal:</p><pre>curl &lt;https://get.datree.io&gt; | /bin/bash</pre><p>For different installation instructions, please have a look at the <a href="https://hub.datree.io/">Datree documentation.</a></p><p>When you run the example test command, you will be provided with the link to the UI Dashboard:</p><pre>datree test ~/.datree/k8s-demo.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Z5vBAoGjTaZuWSqiWb4oQ.png" /><figcaption>Link to the Datree Dashboard</figcaption></figure><p><strong>Benefits</strong></p><ul><li>All information is recorded in Git</li><li>You can easily share Policies with team members</li><li>It enables you to set different policy settings per environment</li></ul><p>Next, open the link that is highlighted in the above screenshot. Your link will likely be slightly different.</p><p>Note that if the Dashboard does not open right away, try to press ctrl + click on the link.</p><p>This will take us to the Datree Dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVsOspOOyuNKyLJwG9Kzog.png" /><figcaption>Policies defined in the UI</figcaption></figure><p>As you can see, I currently have only one policy defined. This policy has 19 rules. I can toggle and untoggle, as well as edit rules from the UI.</p><p>If you are following GitOps best practices, you would only want to allow users to change the settings through starting a PR in Git. If someone was to modify policies through the UI while you keep your policies in Git, it would cause a lot of confusion.</p><p>Thus, we need to tell Datree that we want to use just Policies as Code without allowing edits through the UI.</p><p>To enable Policy as Code, head over to <strong>Your Account</strong> (top left) &gt; <strong>Settings;</strong> next**:**</p><ol><li>Enable Policy as Code</li><li>Download the policies.yaml file</li></ol><p>This file will contain all the default policies. You can also see an example in the documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*rqRsrmY9-TKVB0sdWQA2Tw.png" /><figcaption>Enable Policy as Code in the UI</figcaption></figure><h3>Modify and apply policies</h3><p>Below is an example section from the policies.yaml file:</p><pre>apiVersion: v1<br>policies:<br>  - name: Default<br>    isDefault: true<br>    rules:<br>      - identifier: CONTAINERS_MISSING_IMAGE_VALUE_VERSION<br>        messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant “version surprises” in the future<br>      # - identifier: K8S_INCORRECT_KIND_VALUE_POD<br>      #   messageOnFailure: Incorrect value for key `kind` - raw pod won&#39;t be rescheduled in the event of a node failure</pre><p>Let’s go through the file:</p><ul><li>name: The name specifies how our policy rule is called. If we have multiple different environments, we have to tell Datree which policies we want to use upon running “datree test”</li><li>isDefault: This option allows us to define which policy is being used if we have multiple defined and do not specify which one to use upon running “datree test”</li><li>identifier: Currently, the identifier is provided by Datree and cannot be changed. Take a look at the documentation to learn more about which rules and related identifiers are available.</li><li>messageOnFailure: This is the message provided to the user to learn more about what went wrong. Note that you can provide links and @GitHub-name to tag people in the message.</li><li>The last two lines are commented out. Either delete or comment out the policies that you currently do not want to use for future reference.</li></ul><p>Make sure that each line is indented correctly.</p><p>We are going to modify the file for our staging and for our production environment.</p><p>policies.yaml</p><pre>apiVersion: v1<br>policies:<br>  - name: Staging<br>    isDefault: true<br>    rules:<br>      - identifier: CONTAINERS_MISSING_IMAGE_VALUE_VERSION<br>        messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant “version surprises” in the future<br>      - identifier: CRONJOB_INVALID_SCHEDULE_VALUE<br>        messageOnFailure: &#39;Incorrect value for key `schedule` - the (cron) schedule expressions is not valid and therefor, will not work as expected&#39;<br>      - identifier: WORKLOAD_INVALID_LABELS_VALUE<br>        messageOnFailure: Incorrect value for key(s) under `labels` - the vales syntax is not valid so it will not be accepted by the Kuberenetes engine<br>      - identifier: WORKLOAD_INCORRECT_RESTARTPOLICY_VALUE_ALWAYS<br>        messageOnFailure: Incorrect value for key `restartPolicy` - any other value than `Always` is not supported by this resource<br>      - identifier: HPA_MISSING_MAXREPLICAS_KEY<br>        messageOnFailure: Missing property object `maxReplicas` - the value should be within the accepted boundaries recommended by the organization<br>      - identifier: WORKLOAD_INCORRECT_NAMESPACE_VALUE_DEFAULT<br>        messageOnFailure: Incorrect value for key `namespace` - use an explicit namespace instead of the default one (`default`)<br>      - identifier: DEPLOYMENT_INCORRECT_REPLICAS_VALUE<br>        messageOnFailure: Incorrect value for key `replicas` - don&#39;t relay on a single pod to do all of the work. Running 2 or more replicas will increase the availability of the service<br>      - identifier: K8S_DEPRECATED_APIVERSION_1.16<br>        messageOnFailure: Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (&gt;=1.16)<br>      - identifier: K8S_DEPRECATED_APIVERSION_1.17<br>        messageOnFailure: Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (&gt;=1.17)<br>      - identifier: CONTAINERS_INCORRECT_PRIVILEGED_VALUE_TRUE<br>        messageOnFailure: Incorrect value for key `privileged` - this mode will allow the container the same access as processes running on the host<br>      - identifier: CRONJOB_MISSING_CONCURRENCYPOLICY_KEY<br>        messageOnFailure: Missing property object `concurrencyPolicy` - the behavior will be more deterministic if jobs won&#39;t run concurrently<br>      - identifier: HPA_MISSING_MINREPLICAS_KEY<br>        messageOnFailure: &#39;Missing property object `minReplicas` - the value should be within 3 to 5 pods. Please contact @AnaisUrlichs for further information. &#39;<br>      - identifier: SERVICE_INCORRECT_TYPE_VALUE_NODEPORT<br>        messageOnFailure: &#39;Incorrect value for key `type` - `NodePort` will open a port on all nodes where it can be reached by the network external to the cluster. Please use ClusterIP instead. Contact @AnaisUrlichs for further information. &#39;<br> - name: Prod<br>   isDefault: false<br>   rules:<br>      - identifier: CONTAINERS_MISSING_IMAGE_VALUE_VERSION<br>        messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant “version surprises” in the future<br>      - identifier: K8S_INCORRECT_KIND_VALUE_POD<br>        messageOnFailure: Incorrect value for key `kind` - raw pod won&#39;t be rescheduled in the event of a node failure<br>      - identifier: CONTAINERS_MISSING_MEMORY_REQUEST_KEY<br>        messageOnFailure: Missing property object `requests.memory` - value should be within the accepted boundaries recommended by the organization.<br>      - identifier: CONTAINERS_MISSING_MEMORY_REQUEST_KEY<br>        messageOnFailure: Missing property object `requests.memory` - value should be within the accepted boundaries recommended by the organization.<br>      - identifier: CONTAINERS_MISSING_CPU_REQUEST_KEY<br>        messageOnFailure: Missing property object `requests.cpu` - value should be within the accepted boundaries recommended by the organization<br>      - identifier: CONTAINERS_MISSING_MEMORY_LIMIT_KEY<br>        messageOnFailure: Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization<br>      - identifier: CONTAINERS_MISSING_CPU_LIMIT_KEY<br>        messageOnFailure: Missing property object `limits.cpu` - value should be within the accepted boundaries recommended by the organization</pre><p>As you can tell, I have set different policies for my staging environment and for my production environment. Instead of duplicating policies, you could either run both files before deploying to production or only allow them to deploy to staging if all the policies have passed.</p><p>This file is going to be used to tell Datree about the policies that we want to have in place for different environments. This file is not going to be used to check the policies e.g. during our CI/CD pipeline build.</p><p><strong>Apply the policies</strong></p><p>We want to let Datree know of our changing policies. This can be done with the following command.</p><pre>datree publish policies.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*nMdW4FCAwJKPLUU-6wnx1A.png" /><figcaption>Publish your policies to Datree</figcaption></figure><p>Note that if it cannot find the command, it likely is the case that you had Datree installed before. Make sure to update Datree by following the <a href="https://hub.datree.io/">installation instructions.</a></p><p>Once you run the command, we should see our new policies within the UI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E7zApQA_YfC2iB473_6JyA.png" /><figcaption>Policies as Code visible in the UI</figcaption></figure><p>In this case, you will not be able to change the policies in the UI like discussed earlier in this post.</p><h3>Test Kubernetes manifests for misconfiguration</h3><p>I want to deploy my containerized application to my Kubernetes cluster. However, before doing so, I want to ensure that it does not contain any misconfiguration and complies with the policy rules that I set earlier.</p><p>This is my deployment.yaml:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: react-application<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      run: react-application<br>  template:<br>    metadata:<br>      labels:<br>        run: react-application<br>    spec:<br>      containers:<br>      - name: react-application<br>        image: anaisurlichs/react-example-app:7.0.0<br>        ports:<br>          - containerPort: 80<br>        imagePullPolicy: Always</pre><p>Let’s run the following command to test our deployment manifest:</p><pre>datree test ./manifests/deployment.yaml -p Staging</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*easekSRDebenEXoLad1vDg.png" /><figcaption>Test Manifests on Staging</figcaption></figure><pre>datree test ./manifests/deployment.yaml -p Prod</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KM80dhlkWbSlRr6GY74u1g.png" /><figcaption>Test Manifests on Prod</figcaption></figure><p>As you can see, 6 of our rules have failed. Now we are going to correct our Kubernetes manifest for our deployment so that our rules pass. This is the updated deployment.yaml:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: react-application<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      run: react-application<br>  template:<br>    metadata:<br>      labels:<br>        run: react-application<br>    spec:<br>      containers:<br>      - name: react-application<br>        image: anaisurlichs/react-example-app:7.0.0<br>        ports:<br>          - containerPort: 80<br>        imagePullPolicy: Always<br>        resources:<br>          limits:<br>            memory: 512Mi<br>            cpu: 500m<br>          requests:<br>            memory: 256Mi<br>            cpu: 500m</pre><p>Once you make those updates to your deployment.yaml, all of the policies that we had defined earlier should pass:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*hGz4EBSe53AN9TzPU1wqlA.png" /><figcaption>Tests on Prod passing</figcaption></figure><p>To access our application, we can use the following service.yaml</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: react-application<br>  labels:<br>    run: react-application<br>spec:<br>  type: NodePort<br>  ports:<br>  - port: 8080<br>    targetPort: 80<br>    protocol: TCP<br>    name: http<br>  selector:<br>    run: react-application</pre><p>Assuming you are connected to a Kubernetes cluster, you can now apply both resources.</p><p>If you do not have a Kubernetes cluster available, either sign-up to <a href="http://civo.com/">Civo.com</a> and create a free account today (you will get $250 worth of credit upon sign-up) or create a kind cluster:</p><pre>brew install kind</pre><pre>kind create cluster datree</pre><p>Alternative installation options can be found <a href="https://kind.sigs.k8s.io/docs/user/quick-start/">in the KinD documentation.</a></p><p>Now create a new namespace. In our case, we are going to call it datree:</p><pre>kubectl create ns datree</pre><pre>kubectl apply -f deployment.yaml -n datree<br>kubectl apply -f service.yaml -n datree</pre><p>Lastly, we are going to have a look at the resources listed in the datree namespace:</p><pre>kubectl get all -n datree</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rLZL8wtNszNYF04fXZgorQ.png" /><figcaption>All resources related to our deployment running within our cluster</figcaption></figure><p>You can access the application by running:</p><pre>kubectl port-forward service/react-application 8080:8080 -n datree</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yw-BovuEdYAiOk6YCcRzCQ.png" /><figcaption>Our application</figcaption></figure><h3>Recap ⏪</h3><p>In this blog post, we learnt how we can make effective use of Datree to</p><ul><li>define our Policies as Code</li><li>publish our Policies to Datree</li><li>modify our policies</li><li>test our Kubernetes manifests</li><li>improve our Kubernetes manifest</li><li>deploy our corrected Kubernetes manifests to our Kubernetes cluster</li></ul><p>If you would like to see more on optimising your deployments, please let me know.</p><p>Lastly, make sure to give <a href="https://github.com/datreeio/datree">Datree a GH star</a> and to share this blog post to make sure that others will see it too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/32/0*HRYGjzavK6a2Ov4t.png" /></figure><p>️ If you like Datree, give it a star on <a href="https://github.com/datreeio/datree">GitHub</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/32/0*BgYZZ0K69qFS7hki.png" /></figure><p>Until next time 👋🏼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89753a99c6cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplify Troubleshooting your Kubernetes cluster with Komodor]]></title>
            <link>https://anaisurl.medium.com/simplify-troubleshooting-your-kubernetes-cluster-with-komodor-29433cf58cc2?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/29433cf58cc2</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 12:15:53 GMT</pubDate>
            <atom:updated>2021-10-06T12:15:53.053Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5tln9GEyBWp_lQ0CuKh3SA.png" /></figure><blockquote>Are you at <a href="https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/">KubeCon NA</a>? Make sure to visit Komodor’s booth to get more information, ask questions and for the option to win amazing prizes!!</blockquote><p>When you are using Kubernetes, you will sooner or later run into the problem of having to debug an application with multiple dependencies across your cluster. This can be a highly time-consuming and difficult task, which is made harder by linked dependencies between your Kubernetes resources. In this case, one resource might throw errors while the underlying cause lies within a completely different resource or change that appears to be healthy.</p><p>To properly debug those scenarios, we want to make use of cloud native tools and platforms that provide us with visibility into our cluster and context on the resources running within. One of these tools is Komodor.</p><p>Komodor is a troubleshooting platform for Kubernetes-based environments. It tracks changes and events across the entire system’s stack and provides the needed context to troubleshoot issues efficiently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DaQbzhkHqu8R-5yQy17rEA.png" /><figcaption>Description: Komodor Dashboard Overview Service Explorer</figcaption></figure><p><strong>This blog post will</strong></p><ul><li>Introduce you to Komodor and provide you with an overview of the platform</li><li>Showcase how you can connect your Kubernetes cluster with Komodor</li><li>Detail additional features provided by Komodor</li></ul><p>In the next blog post, we are going to look at a specific use case to showcase how Komodor can be used to debug our Kubernetes resources.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9eC24tzJxSY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9eC24tzJxSY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9eC24tzJxSY%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/16e2b290ec31b4a957a01ea69087b382/href">https://medium.com/media/16e2b290ec31b4a957a01ea69087b382/href</a></iframe><h3>Komodor Overview</h3><p>Komodor allows us to gain the highest visibility into the resources that are running within our cluster. Once we provide the platform with access to our cluster [read-only permissions], we will see</p><ul><li>Any changes that took place</li><li>The resources that were changed</li><li>Who made changes to our resources</li><li>The timeline of those changes</li><li>The health status of our Kubernetes resources</li><li>Kubernetes resource logs [down to the pod level]</li></ul><p>This information helps us to gain an overview of our resources. In case that something goes wrong, we will have the information and tools to quickly troubleshoot our processes and deployments.</p><p><strong>Who should use Komodor and why?</strong></p><p>While the use of Komodor requires an organisation to already have shifted or being in the process of shifting to Kubernetes, anyone who is interacting with Kubernetes deployments will benefit from Komodor. Overall, Komodor is a highly versatile tool. It can be used by DevOps and SRE teams to gain additional insight into the current state of our cluster but also help Developers to better understand the link between changes in Git and the deployed resources.</p><p>Currently, the most common troubleshooting tools are “kubectl” and k9s or similar tools that provide an overview of the cluster and the resources running within. The problem with those tools is that they have a steep onboarding curve and require engineers to manually query the resources within the cluster to find the underlying cause of an error. Similarly, those tools not only allow to view resources but also to delete resources. Having to debug an application at 3 AM and digging through the logs to find the resources that are not operating correctly can easily introduce more errors.</p><p>Furthermore, Komodor provides additional, curated information from across different integrations. With this, it is used in addition to Monitoring solutions, such as Grafana. Monitoring solutions provide a picture of what is going on within the cluster. However, most require users to manually understand the changes that took place by viewing Git events and connecting those to the metrics. As you can imagine, this can result in a lot of guesswork and solutions by trial-and-error. For this purpose, Komodor provides a unique solution. As an SRE, I enjoy having a single go-to-place where I can integrate other tools and see the combined data output of those. During an incident, I am then quicker to understand past events and changes made to the resources within our cluster.</p><p>Komodor provides an easy to use overview of the cluster state and resources within. Using monitoring and manual troubleshooting solutions often requires comprehensive onboarding and sometimes even years of experience. How often does a developer have to use PromQL to query Prometheus or kubectl to view Kubernetes event logs? Through Komodor, developers are able to view the aggregated information from several tools to easily understand how the changes deployed in Git affect resources running within the cluster. Also, novice developers, who have never worked with Kubernetes directly, will not require subject-specific knowledge to use Komodor.</p><h3>Getting started</h3><p>This section will provide an overview of Komodor and its features.</p><p>At the time of writing this blog entry, Komodor does not provide a “self-serve” installation. To gain access to the platform itself, you can register your interest through a simple <a href="https://komodor.com/sign-up/">sign-up flow</a> and then start your free trial.</p><p>Prerequisites:</p><ul><li><a href="https://helm.sh/">Helm </a>installed</li><li><a href="https://www.civo.com/learn/creating-a-cluster-the-path-to-success">A Kubernetes Cluster</a></li><li><a href="https://komodor.com/sign-up/">Access to the Komodor Platform</a></li></ul><p>Before we get started, you need to have a Kubernetes cluster. Ideally, your cluster already has resources installed which will make it easier to view all the features available by Komodor. In our case, we are going to use our Civo Kubernetes cluster. Have a look at the <a href="https://www.civo.com/learn/creating-a-cluster-the-path-to-success">following guide</a> on setting up an account and creating a cluster (it should not take longer than 2min — the time it takes to spin up a Civo Kubernetes cluster ;) ).</p><p>Once signed into the platform, we are provided with the dashboard. Without integrating a Kubernetes cluster, there is little that we can do with the platform. Thus, the next step will be to connect our Kubernetes cluster with Komodor. This is done by installing the Komodor Agent into our cluster. Like other cloud native deployments, the Agent is a simple Helm Chart that we will install within our Komodor namespace. Helm is a package manager for Kubernetes; think about it as a way to pack up a set of Kubernetes YAML manifests and deploy those effectively through the command line.</p><p>You can find the documentation for the Helm Chart in the following <a href="https://github.com/komodorio/helm-charts">GitHub repository</a>. The Helm Chart can become handy if you want to modify further values in the Values.yaml file. However, this is something that we will not have to do for the purpose of this tutorial. To connect your Kubernetes cluster to Komodor, the Helm Chart requires several values; one of those values is the API KEY.</p><p>You can find the API KEY on your dashboard by registering a new cluster. Simply provide the cluster name and you will receive the commands filled out with the necessary information. Note that the actual cluster name and the name that you provide Komodor do not have to be exactly the same. However, we will provide the same name to avoid confusion.</p><p>Commands provided to install the Helm Chart:</p><p>```<br>helm repo add komodorio <a href="https://helm-charts.komodor.io/">https://helm-charts.komodor.io</a></p><p>helm repo update</p><p>helm upgrade — install k8s-watcher komodorio/k8s-watcher — set apiKey=YOUR_API_KEY_HERE — set watcher.clusterName=CLUSTER_NAME</p><p>```</p><p>You can find the API key by accessing the <strong>Integrations </strong>section in the Dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1Y1SBq-h1gVCG7Xa0uqQw.png" /><figcaption>API Key from the integrations section</figcaption></figure><p>Your terminal output should be similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M9kUxWMP6iFec9zCrgNnHg.png" /><figcaption>Komodor Helm Chart installation with specific values</figcaption></figure><h3>The Komodor Dashboard</h3><p>Now that we have added Komodor to our cluster, the agent will push information out of our cluster to the Komodor platform. This is a more secure model than accessing the Kubernetes cluster from outside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DZ1Q4jDqMN_695JaS4L7wA.png" /><figcaption>Komodor Agent and UI Overview</figcaption></figure><p>Going back to the Komodor Dashboard, you should now be able to see the resources from your cluster:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DaQbzhkHqu8R-5yQy17rEA.png" /><figcaption>Komodor Dashboard Overview Service Explorer</figcaption></figure><h3>Filters</h3><p>Let’s take a closer look at the filter section on the left side of the dashboard. As you can see in the screenshot below, we can filter not only per cluster but also per namespace, health and type of deployment. In case that you have multiple environments or a multi-cluster set-up, this will be extremely useful. You can even create your own customizable filters that make sense to your use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*7eQYVdvCvr3IKrae9CvUZg.png" /><figcaption>Option to filter resources in the UI</figcaption></figure><h4><strong>Time zone</strong></h4><p>It is worth mentioning the level of considerations taken in the design of the platform. Working with a remote team, not all team members are going to be in the same time zone. Komodor makes it really easy to change the timezone in the top right of the Dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*yLh0LT4FZ6sCLDm1jrf-qA.png" /><figcaption>Select your timezone in the Dashboard</figcaption></figure><h4><strong>Services</strong></h4><p>Next, we can click into a specific service to see further detail on</p><ul><li>The state of the service</li><li>Any changes that have been made to the service over time</li><li>Related services</li></ul><p>In case that one of the services goes down without showing any visible changes, it is often useful to check related resources and the changes that have been made to those. A change in another Kubernetes resource might trigger a part of our cluster and resource that we would not necessarily think of.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*98VnEMPRnVDQt0bAeNVLmw.png" /></figure><p>Furthermore, by selecting related services, it is possible to overlay the events of multiple services to find correlations between Events and Services fast. This makes it even easier to debug the changes that happened within your cluster.</p><h3><strong>Live Pod Status and Logs</strong></h3><p>From the specific service, we can click into the pods that are connected to the service “Pods status and Log” on the left of the UI. This will provide us with the Description, Logs, and Events related to the service. These are usually information that you either find through a combination of kubectl commands or by using specific tools such as k9s. However, Komodor is the first platform (that I came across) with a comprehensive UI that provides intuitive access to the logs and events of individual pods.</p><p>To access this feature, we will have to enable the following flag in the Komodor Agent Helm Chart: watcher.enableAgentTaskExecution</p><p>```<br>helm upgrade — install k8s-watcher komodorio/k8s-watcher — set watcher.enableAgentTaskExecution=true — reuse-values<br>```</p><p>Once enabled, you will see your resource, events, and logs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*43TqKgz0oyZFRG-UaMnoJA.png" /><figcaption>Live Status and Logs of the Pods</figcaption></figure><h3><strong>Events</strong></h3><p>While the <em>Services </em>section provides an overview of the different services running within our cluster to receive the highest insights into specific resources, the <em>Events </em>section displays the changes that have occurred within our cluster over time. Additionally, the Events section allows us to combine resources and see all events, regardless of the cluster or resource, selected. Those events may include any changes in our deployments or information on resources within our cluster. The information is largely provided by our integrations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ag3mjQoe6AVJ_XDosAOOw.png" /><figcaption>Events section in the Komodor Dashboard</figcaption></figure><p>By selecting a specific event, we can see further information on the Git or a similar event that took place:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*291iDNiF0ZQK5_FLiNK_CQ.png" /><figcaption>Events section with further details on deployments</figcaption></figure><p>Note that Komodor does not only track automatic changes that have taken place through Git but also manual changes that have been directly applied to the cluster. Thus, if someone makes any changes directly to the cluster without pushing to Git, those changes will also become visible within the Dashboard.</p><p>Each section has a link that will provide you with specific documentation on setting up the integration. Most of the integrations simply require users to add annotations and labels to their Kubernetes Deployments. Once you have set up the integration with Git and Slack, you will receive further information on events.</p><h3><strong>Integration</strong></h3><p>The last section that I want to highlight is the integration section. Regardless of how good a tool is, if it does not provide the right integrations with other tools and platforms, it is likely going to be of little use.</p><p>This is not the case with Komodor, which offers several integrations with related monitoring and troubleshooting tools. Once you set up a new integration, it will provide additional data points to your Services and Events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I1vgj79zOrPsE92z_SaNog.png" /><figcaption>Komodor integration page</figcaption></figure><p><strong>Integrating with Slack requires you to</strong></p><ol><li>Give Komodor Access to your Slack Account</li><li>Add the necessary annotations to your deployments e.g.</li></ol><p>```</p><p>app.komodor.com/notification.deploy.slack: “#deploy”</p><p>app.komodor.com/notification.alert.slack: “#p1-health-issues”<br>```</p><p>Done!</p><p>Komodor provides you with the possibility to add <a href="http://app.komodor.com/notification.deploy.slack:%20%22#deploy%22%20%20%20%20%20app.komodor.com/notification.alert.slack:%20%22#p1-health-issues%22">custom rules</a> within the annotations.</p><p>Note that if you are an organisation and you require custom integration, please <a href="https://komodor.com/contact-us/?swcfpc=1">reach out</a> directly to the Komodor team. They are consistently working on adding new features to the platform and are quick to respond to user requests. For instance, since I have been working on this tutorial, the platform has had two major features added :)</p><h3>What’s Next?</h3><p>In this blog post, we saw how and why we would want to use Komodor, we went through the process of installing the Komodor Agent into our Kubernetes cluster to receive information on the resources within and took a tour through the Komodor Platform to understand its features.</p><p>In the next tutorial, we are going to have a look at specific use cases to see how we can use Komodor to debug issues within our Kubernetes resources.</p><p>In the meantime, have a look at the resources provided by Komodor. They have great <a href="https://komodor.com/blog/">content on their blog</a> and comprehensive, on-demand webinars.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29433cf58cc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Full Tutorial — Deploying Helm Charts in Kubernetes with Terraform]]></title>
            <link>https://anaisurl.medium.com/full-tutorial-deploying-helm-charts-in-kubernetes-with-terraform-5bade71dc293?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bade71dc293</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Wed, 29 Sep 2021 12:06:26 GMT</pubDate>
            <atom:updated>2021-09-29T12:06:26.698Z</atom:updated>
            <content:encoded><![CDATA[<h3>Full Tutorial — Deploying Helm Charts in Kubernetes with Terraform</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1-znXt1Xinzuu3ShI2voFQ.png" /><figcaption>Terraform blog post thumbnail</figcaption></figure><p>I previously created a video on Terraform. However, at the time, I was completely new to Terraform. Thus, I thought it would be really valuable to create an updated guide on using Terraform. Once you go through the “basics” it becomes easier to use Terraform for more advanced use cases. Specifically, in this tutorial, I will highlight how to use Terraform for Helm deployments.</p><p>Below is the video tutorial that follows this blog post. Feel free to use either resource.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQq1cfVw1Mx4&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQq1cfVw1Mx4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3eee63d713ab4c024cc814e7e92cfb4/href">https://medium.com/media/e3eee63d713ab4c024cc814e7e92cfb4/href</a></iframe><p><strong>What is Terraform?</strong></p><p>Let’s quickly recap. Here is the definition by HashiCorp — who created Terraform;</p><blockquote><em>Terraform is an open-source infrastructure as Code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files.</em></blockquote><p>Meaning, Terraform can be used as an Infrastructure as Code tool to manage our entire infrastructure and the resource we deploy on it. Resulting, all of our resources can be declared and tracked in Git — this, in turn, makes it possible to follow GitOps best practices whereby our single point truth for all of our resources is Git. To learn more about GitOps, please <a href="https://thenewstack.io/understanding-gitops-the-latest-tools-and-philosophies/?_lrsc=8152a3b4-7d91-4727-837d-83935ee7bd67">have a look at this article.</a></p><p><strong>What are we going to cover?</strong></p><p>While there are lots of introductory videos, I feel like what is missing is a video that would show the entire process for using Terraform, not only to manage your infrastructure but also to create and manage your workloads on Kubernetes. To follow this tutorial, you do not need to have any Terraform experience. However, I highly suggest you have a look at my previous videos and content on Helm:</p><ul><li><a href="https://youtu.be/hOaA_VYhKV8">Practical Introduction to Helm: Day 21 of #100DaysOfKubernetes</a></li></ul><p><strong>This tutorial is taking a look at</strong></p><ul><li>Installing Terraform</li><li>Creating a Kubernetes cluster with Terraform</li><li>Creating a Helm Chart for our application</li><li>Testing our Helm Chart with Datree</li><li>Deploying our Helm Chart to our cluster</li></ul><p>You can find all the resources that we are going to create in the <a href="https://github.com/AnaisUrlichs/terraform-helm-example">following Git repository.</a></p><p>So let’s get started! 🎉</p><h3>Installing Terraform</h3><p>First, you want to make sure that you have the Terraform CLI installed. You can find the documentation on the <a href="https://learn.hashicorp.com/tutorials/terraform/in">Terraform docs</a>. I would recommend having brew installed and using brew:</p><pre>brew tap hashicorp/tap</pre><pre>brew install hashicorp/tap/terraform</pre><p>Pro tip: You can also install brew for Linux</p><p>If you are already using Terraform, make sure to upgrade to the latest version</p><pre>brew update</pre><pre>brew upgrade hashicorp/tap/terraform</pre><p>Now run ‘terraform’ just to make sure that you have it installed and it is working properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*-hxwacxkbDpQjXMYkYebLg.png" /><figcaption>terraform command</figcaption></figure><h3>Creating a Kubernetes cluster with Terraform</h3><p>First, we want to create a cluster on which we can then deploy our Helm chart.</p><p>In my case, I am going to use Civo, however, you can also use other cloud providers. If you want to use the Azure Kubernetes Service, you could for example Google “Azure Terraform Provider” to find the provider documentation. The documentation will tell you how to create a Kubernetes cluster on the given provider. To follow this exact tutorial, go ahead and <a href="https://www.civo.com/">set up a new Civo Account</a>. With every new sign-up, you will get $250 worth of credits.</p><p>To set up the Civo Terraform provider, we will need the API Key. You can find your Civo API key in Account &gt; Settings &gt; Security.</p><p>Now create a provider.tf file and paste in the following content:</p><pre>provider &quot;civo&quot; {<br>  token = &lt;your API token&gt;</pre><pre>}</pre><pre>terraform {<br>  required_version = &quot;&gt;= 0.13.0&quot;<br>  required_providers {<br>    civo = {<br>      source = &quot;civo/civo&quot;<br>    }<br>  }<br>}</pre><pre>provider &quot;kubernetes&quot; {<br>  host     = data.civo_kubernetes_cluster.cluster.api_endpoint<br>  client_certificate = base64decode(<br>    yamldecode(civo_kubernetes_cluster.cluster.kubeconfig).users[0].user.client-certificate-data<br>  )<br>  client_key = base64decode(<br>    yamldecode(civo_kubernetes_cluster.cluster.kubeconfig).users[0].user.client-key-data<br>  )<br>  cluster_ca_certificate = base64decode(<br>    yamldecode(civo_kubernetes_cluster.cluster.kubeconfig).clusters[0].cluster.certificate-authority-data<br>  )<br>}</pre><p>Next, replace &lt;your API token&gt; with your actual API token.</p><p>Once you have the file, go ahead and run the following command to initialize the provider.</p><pre>terraform init</pre><p>Awesome, now we can move to the next step of creating our Kubernetes cluster and then creating our Helm Chart.</p><h3>Creating and managing your Kubernetes cluster through Terraform</h3><p>Create a new file called cluster.tf or similar</p><pre>resource &quot;civo_kubernetes_cluster&quot; &quot;cluster&quot; {<br>  name              = &quot;terraform-example&quot;<br>  applications      = &quot;&quot;<br>  num_target_nodes  = 3<br>  target_nodes_size = element(data.civo_instances_size.small.sizes, 0).name<br>  region            = &quot;LON1&quot;<br>}</pre><pre>data &quot;civo_kubernetes_cluster&quot; &quot;cluster&quot; {<br>  name = civo_kubernetes_cluster.cluster.name<br>}</pre><pre>data &quot;civo_instances_size&quot; &quot;small&quot; {<br>    filter {<br>        key = &quot;type&quot;<br>        values = [&quot;kubernetes&quot;]<br>    }<br>}</pre><p>Now we can already go ahead and deploy the resource. To see any changes between the current state of your infrastructure and its desired state, run</p><pre>terrafor plan</pre><p>This command will show you any resources that terraform has to change, create, or destroy that the current state of your infrastructure matches the desired state defined in Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cCJNWDQhW_6uHgmorwT_oQ.png" /></figure><p>You should see an output similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*qA2dw575Wv_dx8_TUwkypw.png" /><figcaption>terraform plan output</figcaption></figure><p>If you are happy with the changes that terraform will make within your cluster, run the following command:</p><pre>terrafrom apply</pre><p>This will tell Terraform that you are ok with the changes that it is going to make.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*jgXpFJH6Z405dJQD5c9cGA.png" /><figcaption>accept changes after terraform apply</figcaption></figure><p>Let’s go one step further and set up a variables.tf file in which we can dynamically define the variables that we want to use within our terraform deployment.</p><p>in that file, we are going to post something like:</p><pre>variable &quot;civotoken&quot; {<br>  default = &quot;&lt;replace with your token&quot;<br>  type = string<br>}</pre><pre>variable &quot;cluster_name&quot; {<br>  default = &quot;terraform-example&quot;<br>}</pre><pre>variable &quot;cluster_nodes&quot; {<br>  default = &quot;3&quot;<br>}</pre><pre>variable &quot;region&quot; {<br>  default = &quot;LON1&quot;<br>}</pre><pre>variable &quot;applications&quot; {<br>  default = &quot;&quot;<br>}</pre><p>Now we can update the values in the cluster.tf file with “var.name_of_the_variable” so for instance, our cluster.tf file will now become:</p><pre>resource &quot;civo_kubernetes_cluster&quot; &quot;cluster&quot; {<br>  name              = var.cluster_name<br>  applications      = var.applications<br>  num_target_nodes  = var.cluster_nodes<br>  target_nodes_size = element(data.civo_instances_size.small.sizes, 0).name<br>  region            = var.region<br>}</pre><pre>data &quot;civo_kubernetes_cluster&quot; &quot;cluster&quot; {<br>  name = civo_kubernetes_cluster.cluster.name<br>}</pre><pre>data &quot;civo_instances_size&quot; &quot;small&quot; {<br>    filter {<br>        key = &quot;type&quot;<br>        values = [&quot;kubernetes&quot;]<br>    }<br>}</pre><p>Don’t forget to also update the Civo token reference in the <a href="http://provider.tf/">provider.tf</a> file with “var.civotoken”.</p><p>Making this change early on will allow us to dynamically define values over time, which will potentially save us a lot of struggle later on.</p><h3>Adding the Helm Provider</h3><p>Helm is a really powerful Kubernetes-based tool. Most of our cloud-native applications have a Helm Chart that can be used to configure, install and manage our application. Think about Helm like a package manager for your cloud-native applications.</p><p>For this example, we will install the Prometheus Operator Helm Chart through Terraform and then also a custom Helm Chart.</p><p>You can find the Helm Provider documentation here: <a href="https://registry.terraform.io/providers/hashicorp/helm/latest/docs">https://registry.terraform.io/providers/hashicorp/helm/latest/docs</a></p><p>We can add the Helm Provider in our provider.tf file with the following lines:</p><pre>provider &quot;helm&quot; {<br>    kubernetes {<br>    host     = data.civo_kubernetes_cluster.cluster.api_endpoint<br>    client_certificate = base64decode(<br>      yamldecode(civo_kubernetes_cluster.cluster.kubeconfig).users[0].user.client-certificate-data<br>    )<br>    client_key = base64decode(<br>      yamldecode(data.civo_kubernetes_cluster.cluster.kubeconfig).users[0].user.client-key-data<br>    )<br>    cluster_ca_certificate = base64decode(<br>      yamldecode(data.civo_kubernetes_cluster.cluster.kubeconfig).clusters[0].cluster.certificate-authority-data<br>    )<br>  }<br>}</pre><p>As you can see, this is pretty similar to our Kubernetes provider configuration just that the information is passed into the Helm provider.</p><p>Since we are adding the provider, we have to run the following command again to initialise it:</p><pre>terraform init</pre><p><strong>Where does the data to allow Helm to connect to our Civo Kubernetes Cluster come from?</strong></p><p>Earlier, we defined our Civo Kubernetes cluster and stored the information in a data object. You can query the object. First, have a look at the Terraform State that Terraform currently knows about and tracks:</p><pre>terraform state</pre><p>This will give you a list of objects.</p><p>Next, open up the terraform console:</p><pre>terraform console</pre><p>And lastly, pass in one of the data objects that have been returned by querying the Terraform State:</p><pre>data.civo_kubernetes_cluster.cluster</pre><p>This should return all of the values known to your Kubernetes cluster.</p><h3>Creating a Helm Release</h3><p>Next up, we are going to create a new directory within our folder that will keep all of our custom Helm Charts:</p><ol><li>charts — in this directory we are going to create all of our custom Helm Charts</li></ol><p>First, we are going to add a custom Helm chart to the charts directory. For this, I am going to add the example Helm Chart that comes with the Helm create command. You can either follow the steps outlined below or add your own custom charts into the charts directory.</p><pre>cd charts<br>helm create nginx</pre><p>You should now see the nginx example chart provided by Helm, ready to be deployed.</p><h3>Test Chart Manifests with Datree</h3><p><a href="https://www.datree.io/?utm_source=Anais&amp;utm_medium=article&amp;utm_campaign=Helm+Deployments+with+Terraform&amp;utm_id=influencer">Datree </a>helps us to prevent Kubernetes misconfigurations from reaching production. When we add a new Helm Chart or other Kubernetes-based resources, we want to make sure that those are configured correctly before deploying them.</p><p>I have done an entire video on Datree before. So if you want to learn more about Datree, I highly suggest you to have a look at that:</p><ul><li><a href="https://youtu.be/MpdhrabnpYs">Verify Kubernetes Deployments with Datree</a></li></ul><p>Datree provides a helm integration that allows us to check the manifests that will be created through our Helm Chart.</p><p>If you do not have Datree installed yet, go ahead and add it:</p><pre>curl &lt;https://get.datree.io&gt; | /bin/bash</pre><p>Now, when you run “datree” you should see a list of options in your CLI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BsKdPwUaTmd-ebLAn6KJTw.png" /><figcaption>datree test command output</figcaption></figure><p>Now you can test Kubernetes manifests by running:</p><pre>datree test ./file.yaml</pre><p>However, to test our Helm Chart, we are going to use the Help plugin directly. Helm plugins can be used to extend the functionality of Helm. Let’s go ahead and add the Datree Helm integration:</p><pre>helm plugin install &lt;https://github.com/datreeio/helm-datree&gt;</pre><p>Once added, we can test our Helm chart directly. From the root directory run:</p><pre>helm datree test ./charts/nginx</pre><p>This should give us output similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZXo37oBCwCs4zNFgAb4Ycg.png" /></figure><p>Once we know about the policies that have not passed our check, we can improve our Helm Chart.</p><p>Using <a href="https://www.datree.io/?utm_source=Anais&amp;utm_medium=article&amp;utm_campaign=Helm+Deployments+with+Terraform&amp;utm_id=influencer">Datree</a> we can not only test our deployments manually on our local environment but integrate it as part of our CI/CD pipeline once we automate the process.</p><p>Setting up an account is free and will provide you with further insights on your deployments.</p><h3>Add Helm Release</h3><p>Next, let’s add our Terraform Helm releases. These are going to make sure that our Helm charts are going to be deployed. Add the following files within your root repository:</p><p>helm_release_nginx.tf</p><pre>resource &quot;helm_release&quot; &quot;nginx&quot; {<br>  name        = &quot;nginx&quot;<br>  chart       = &quot;nginx&quot;<br>  repository  = &quot;./charts&quot;<br>  namespace   = &quot;application&quot;<br>  max_history = 3<br>  create_namespace = true<br>  wait             = true<br>  reset_values     = true<br>}</pre><p>helm_release_prometheus.tf</p><pre>resource &quot;helm_release&quot; &quot;prometheus&quot; {<br>  name             = &quot;prom&quot;<br>  chart            = &quot;kube-prometheus-stack&quot;<br>  repository       = &quot;https://prometheus-community.github.io/helm-charts&quot;<br>  namespace        = &quot;monitoring&quot;<br>  version          = &quot;17.1.3&quot;<br>  create_namespace = true<br>  wait             = true<br>  reset_values     = true<br>  max_history      = 3<br>}</pre><p>And lastly, we can install the charts through Terraform. First run the following command to see the resources that will be created:</p><pre>terraform plan</pre><p>You should see three resources that will be created. Now apply those resources:</p><pre>terraform apply</pre><p>And voila! We have our Kubernetes Cluster created and the Helm Charts within installed.</p><h3>Let’s recap</h3><p>In this tutorial, we have set up a completely new repository to manage our infrastructure and application deployment through Terraform. We learnt:</p><ul><li>How to use Terraform</li><li>How to initialise providers</li><li>Defined our infrastructure resources</li><li>Set up a custom Helm Chart and manage it through Terraform</li><li>Test our Kubernetes deployments with <a href="https://www.datree.io/?utm_source=Anais&amp;utm_medium=article&amp;utm_campaign=Helm+Deployments+with+Terraform&amp;utm_id=influencer">Datree</a>.</li></ul><h3>Sharing is caring 🤗</h3><p>These tutorials take a long time to prepare. If you enjoyed it, I would highly appreciate seeing a Twitter post from you or similar. It would mean a lot to me.</p><p>If you liked this article, please give it a few claps! You can give up to 50 claps. These tutorials take a long time to prepare and your support would mean a lot to me 🤗</p><h3>Next Up: Terragrunt and Terraform — the dream couple.</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bade71dc293" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#14 DevOps Diary: Learning Go & More Podcasts!]]></title>
            <link>https://anaisurl.medium.com/14-devops-diary-learning-go-more-podcasts-c64728f4d50?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c64728f4d50</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 15:41:35 GMT</pubDate>
            <atom:updated>2021-01-24T15:41:35.286Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dTKV1R92Ok2O3cIl10KAew.png" /></figure><p>Welcome beautiful people!</p><blockquote><em>Motivation comes from doing ♾️</em></blockquote><p>The more I learn about the cloud-native space, tools and platforms, the more excited I get about learning more 🎉</p><p>On other news, I was finally able <a href="https://www.youtube.com/c/AnaisUrlichs?sub_confirmation=1">to customise my YouTube domain!</a> A BIG shout-out to my subscribers for supporting me along my learning journey! You rock 🙌🏼</p><p>Now let’s get started with this week’s content…</p><h3>Videos🎥</h3><p>This week, I will highlight a few YouTube channels that are quite amazing in different ways</p><ul><li><strong>Jeff Geerling</strong>’s <a href="https://www.youtube.com/channel/UCR-DXc1voovS8nhAvccRZhg">YouTube channe</a>l where he shows lots of Raspberry Pi videos + tutorials; he also has a specific Kubernetes 101 tutorial. Have a look if you enjoy hands-on learning.</li><li>Dave Farley’s Channel on <a href="https://www.youtube.com/channel/UCCfqyGl3nq_V0bo64CjZh8g"><strong>Continuous Delivery</strong></a> — Definitely a variety of insights that I would not get in most blog posts or by other YouTubers + he aims to make the content more entertaining by connecting it with current events across industries.</li></ul><p>And next, two amazing, growing channels — check those out if you are into podcast style content</p><ul><li><a href="https://www.youtube.com/channel/UCMZAsRXAPe3BDxZEncXSbGA"><strong>The Popcast</strong></a> by <a href="https://twitter.com/danpopnyc">Dan</a> is going into its second season, featuring lots of amazing people across the cloud-native space.</li></ul><p><a href="https://blog.anaisurl.com/14-devops-diary-learning-go-more-podcasts/"><strong>Have a look at the entire newsletter here</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c64728f4d50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#13 DevOps Diary: Events are back]]></title>
            <link>https://anaisurl.medium.com/13-devops-diary-events-are-back-daf320ae000a?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/daf320ae000a</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 18:04:32 GMT</pubDate>
            <atom:updated>2021-01-17T18:04:32.612Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zHSnAEQyXj3zQ3VvQrrIEg.png" /></figure><p>Welcome beautiful people!</p><p>This week is yet another week full of Kubernetes learning resources. Personally, I started learning Go and I am consistently surprised by the level of support by the community; <a href="https://twitter.com/goinggodotnet/status/1350063893293502465">this is just one example.</a></p><p>Hope you enjoy this week’s newsletter 😊</p><p>If you have any comments, suggestions, anything you would like to have included in next week’s edition, <a href="https://devops.anaisurl.com/contact">please do let me know</a>.</p><h3>Top Kubernetes Learning Resources 📖</h3><p>This is an <a href="https://ramitsurana.gitbook.io/awesome-kubernetes/docs/learning-resources">open source documentation</a>, linking to Kubernetes resources and providing explanations. <a href="https://github.com/ramitsurana/awesome-kubernetes">You can also contribute here</a>.</p><h3>Videos🎥</h3><ul><li>This week, I had the chance to <a href="https://youtu.be/n8ou7brCcLw">spontaneously record an episode on Kubernetes Services</a> with <a href="https://twitter.com/rawkode">David McKay</a> and <a href="https://twitter.com/pst418">Philipp Strube</a> in which I asked all those questions newbies might be wondering about, getting started with Kubernetes. Also, have a look at David McKay’s <a href="https://www.youtube.com/channel/UCrber_mFvp_FEF7D9u8PDEA">YouTube channel</a>.</li><li>If you are new to Kubernetes, or also, if you have already been using Kubernetes for some time, you might want to <a href="https://youtu.be/5Nhbl6LwP2o">check out k9s</a> as part of my #100DaysOfKubernetes series. It is a terminal based UI that allows you to easier manage all your cluster resources.</li></ul><p><a href="https://blog.anaisurl.com/13-devops-diary-events-are-back/"><strong>You can view the full newsletter HERE!</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daf320ae000a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Coverage Reports using Codacy and Codefresh]]></title>
            <link>https://medium.com/containers-101/code-coverage-reports-using-codacy-and-codefresh-92cdf9897a00?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/92cdf9897a00</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[code-coverage]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[codacy]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Thu, 14 Jan 2021 18:19:18 GMT</pubDate>
            <atom:updated>2021-01-14T18:19:18.589Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QceOlQGqgj3KGwOMuSyT6A.png" /></figure><p>Where do you usually track your code coverage? If you are not sure about the answer to this question or you would like to explore other options to the ones that you are currently using, then this post is for you.</p><p>Specifically, this post details how you can use <a href="https://www.codacy.com/">Codacy</a> in your Codefresh pipeline to create and send coverage reports of your repository with every pipeline build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*eJHxh8fxk8C1PTFi.png" /></figure><p>To follow along, make sure to have a <a href="https://www.codacy.com/">Codacy</a> and a<a href="https://codefresh.io/codefresh-signup/"> Codefresh account.</a> If not, <a href="https://codefresh.io/codefresh-signup/?utm_source=Blog&amp;utm_medium=Post&amp;utm_campaign=codacy">now is the time to set-up a fresh account for free</a>!</p><h3>Codacy Overview</h3><p>Codacy is a code review tool that allows for automatic analysis, code coverage tracking, and extensive reports that allow you and your team to improve your code quality over time.</p><p>The goals of Codacy is to provide insights on</p><ul><li>How is your code quality today and</li><li>How is your code quality evolving over time</li></ul><p>Additional features include:</p><ul><li>User management: Mirroring GitHub permissions</li><li>Extensive configuration</li><li>Additional integration with other tools, such as notifications</li><li>Receive analysis reports per file</li><li>Depending on the standards that your team wants to enforce, you can add additional parameters such as coverage thresholds</li></ul><p>Codacy has a <a href="https://www.codacy.com/pricing">free version</a>, a pro version, and an on-premises version. The latter two have a free trial, which allows you to test all features over the course of two weeks. You can sign-up via GitHub, Bitbucket, or GitLab.</p><p>It supports over <a href="https://docs.codacy.com/getting-started/supported-languages-and-tools/">30 different languages</a>. In our example, we’ll be using TypeScript. If you would like to follow along with a different language make sure it is supported by Codacy.</p><p>When you log into Codacy for the first time, it will ask you to <a href="https://docs.codacy.com/getting-started/getting-started-with-codacy/#add-repositories">provide access to a repository.</a> At this stage, Codacy will not download any code from your repository but merely access its names. You can then either provide access to selective repositories or your entire Git repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*sYvGgH8mDAEfP3Kz.png" /></figure><p>After adding a repository, it will automatically update the information recorded about your application in the Dashboard. Codacy’s UI has the following taps:</p><ul><li>The <a href="https://docs.codacy.com/repositories/repository-dashboard/">Dashboard</a> with an overview of issues and code coverage reports</li><li>The <a href="https://docs.codacy.com/repositories/commits-view/">Commits</a>, which provides a history of all commits that are associated with this repository</li><li>The <a href="https://docs.codacy.com/repositories/files-view/">Files</a> within the repository and their respective issues</li><li>The <a href="https://docs.codacy.com/repositories/issues-view/">issues</a> that Codacy identified in our repository</li><li>Open Pull requests</li><li>And lastly, as part of the pro features, users can set-up security alerts.</li></ul><p>We will stick for now with the Dashboard tap.</p><p>As you might be able to tell, the Dashboard does not have access to code coverage reports by default. The next section will provide a guide on connecting Codacy to your code coverage reports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*b4-FybjpPJrBNuKP.png" /></figure><h3>Set-up Codacy</h3><p>To connect Codacy either to our local set-up or to Codefresh, we need an API token. The token can be accessed through the taps in the project. For this, select your <em>project</em> =&gt;<em> go to settings </em>=&gt; <em>integrations</em> =&gt; <em>add integration</em> =&gt; select<em> “Project API”</em>. Make sure that you select the API token from here and not your general project settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*nj2kmLzdZ0EQyEu-.png" /></figure><p>Next, we are going to prepare our project. In our case, we are using a simple <a href="https://github.com/codefresh-contrib/codacy-sample-app">Typescript application</a> and uses <a href="https://jestjs.io/">jest</a> to produce coverage reports.</p><pre>git clone git@github.com:anais-codefresh/codacy-sample-app.git</pre><pre># now cd into the cloned repository<br>cd codacy-sample-app</pre><p>You should then find yourself in the following project structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/0*5T4Pa6saotEtjAXl.png" /></figure><p>To run the application, you can use the following commands:</p><pre>npm install<br>npm run build</pre><p>And to test:</p><pre>npm run test</pre><p>This should produce the following test coverage report:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*1r3r_QYFykbgWJ7Z.png" /></figure><p>Once we have our testing and coverage reports set-up, we can push our changes to our Git repository.</p><h3>Set-up Codefresh</h3><p>The previous section showed how we can set-up our node project with code coverage reports. However, that would not be scalable to continue across machines, versions, or our application, and team members. In this section, we will set-up our Codefresh pipeline to push our code coverage reports to Codacy automatically.</p><p>To follow this section, please have your <a href="https://codefresh.io/codefresh-signup/">Codefresh account</a> ready! And integrate with a container registry e.g. Docker Hub or the GitHub container registry.</p><p>Once we enter the Codefresh platform, we want to create a new Pipeline. Make sure to select the repository in which we set-up our coverage reports:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*jve54Np7OLmBG54R.png" /></figure><p>The pipeline will come with a basic codefresh.yml file. If you are following along, make sure to delete everything that is in the current inline YAML. If you are using your existing pipeline, the next section will show you how to modify the YAML to integrate with Codacy. In the end, we will have the following pipeline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*MSIWtwBocHCDspei.png" /></figure><p>To use Codacy, we will have to modify our pipeline to generate the code coverage reports and then push those to our Codacy account. First, we are going to run our tests inside a node image and then connect to Codacy. Our full pipeline will look as such:</p><pre>version: &quot;1.0&quot;<br># Stages can help you organize your steps in stages<br>stages:<br>  - &quot;clone&quot;<br>  - &quot;build&quot;<br>  - &quot;test&quot;</pre><pre>steps:<br>  clone:<br>    title: &quot;Cloning repository&quot;<br>    type: &quot;git-clone&quot;<br>    repo: &quot;codefresh-contrib/codecov-sample-app&quot;<br>    # CF_BRANCH value is auto set when pipeline is triggered<br>    # Learn more at codefresh.io/docs/docs/codefresh-yaml/variables/<br>    revision: &quot;${{CF_BRANCH}}&quot;<br>    git: &quot;github&quot;<br>    stage: &quot;clone&quot;</pre><pre>  build:<br>    title: &quot;Building Docker image&quot;<br>    type: &quot;build&quot;<br>    image_name: &quot;codefresh-contrib/codecov-sample-app&quot;<br>    working_directory: &quot;${{clone}}&quot;<br>    tag: &quot;${{CF_BRANCH_TAG_NORMALIZED}}&quot;<br>    dockerfile: &quot;Dockerfile&quot;<br>    stage: &quot;build&quot;</pre><pre>  tests:<br>      title: &quot;Running test&quot;<br>      type: &quot;freestyle&quot;<br>      working_directory: &#39;${{clone}}&#39;<br>      arguments:<br>        image: &#39;node:15.2&#39;<br>        commands:<br>          - &quot;npm install --save-dev jest&quot;<br>          - &quot;npm run test&quot;<br>      stage: &quot;test&quot;</pre><pre>  codacy:<br>        title: &quot;Pushing reports to codacy&quot;<br>        type: &quot;freestyle&quot;<br>        working_directory: &#39;${{clone}}&#39;<br>        arguments:<br>          image: &#39;alpine:3.8&#39;<br>          commands:<br>            - &quot;export CODACY_PROJECT_TOKEN=${{CODACY_PROJECT_TOKEN}}&quot;<br>            - &quot;wget -qO - <a href="https://coverage.codacy.com/get.sh">https://coverage.codacy.com/get.sh</a> | sh&quot;<br>        stage: &quot;test&quot;</pre><p>Make sure to</p><ul><li>Change image_name in the build step to your image name in the following format:<br> Container-registry/image-name,</li><li>Change the tag of the image to fit your tag,</li><li>And lastly, replace the image and the commands in the “tests” stage to use the commands of your repository to run tests and create coverage-reports.</li></ul><p>The last step, called “codacy” in this case, is responsible for running the Codacy script. To set the env variable, we are going to export our Codacy project token and add the token in the toolbar that you can find on the right of the UI. Once the variable is called through the Codefresh YAML syntax, it will automatically use the value provided within the variables section. Note that you could also provide your token directly in the YAML; however, once we add the pipeline to our git repository, we do not want to worry about accidentally exposing secrets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/0*VFLeS4L5pzaO8t7X.png" /></figure><p>Once added, we can save and run our pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*386Z2t23LyUv1ShK.png" /></figure><p>You can follow the execution of the pipeline in the output section. The next time that we commit to our repository, a new coverage report will be generated and pushed to our Codacy account through our Codefresh pipeline.</p><h3>View the reports in Codacy</h3><p>Now we can head over to our Codacy account and see the updated data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*e0f4_-wvTydtKJji.png" /></figure><p>Selecting the files tap and a specific file to analyze we can find more information on our code quality:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*Cm92myH0qyyNNXV2.png" /></figure><h3>Let’s Recap</h3><p>Codacy provides a fast way to integrate code coverage into your Codefresh pipeline. It supports over 30 different languages and an extensive dashboard that also displays information on issues, PRs, and your commit history.</p><p>In this tutorial, we set-up coverage reports in our node application, set-up our project in Codacy, and create a Codefresh pipeline with two additional steps.</p><p>If you are new to Codefresh, <a href="https://codefresh.io/codefresh-signup/?utm_source=Blog&amp;utm_medium=Post&amp;utm_campaign=codacy">now is the time to set-up a fresh account for free</a>! Also, <a href="https://community.codefresh.io/">do join our forum</a> and ask away if you have any questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92cdf9897a00" width="1" height="1" alt=""><hr><p><a href="https://medium.com/containers-101/code-coverage-reports-using-codacy-and-codefresh-92cdf9897a00">Code Coverage Reports using Codacy and Codefresh</a> was originally published in <a href="https://medium.com/containers-101">Container Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#12 DevOps Diary: Computer Science and K8s resources]]></title>
            <link>https://anaisurl.medium.com/12-devops-diary-computer-science-and-k8s-resources-4445dc735e01?source=rss-2ac6b7c2915b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4445dc735e01</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[learn]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anaïs Urlichs]]></dc:creator>
            <pubDate>Sun, 10 Jan 2021 16:26:25 GMT</pubDate>
            <atom:updated>2021-01-10T16:26:25.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OfXvgFKqAAJvo6jvjwbs5g.png" /></figure><p>Welcome beautiful people!</p><p>I hope you are all doing well. I was really excited to write this week’s newsletter and share these amazing resources with you. I hope you like them/find them interesting 😊</p><p>Remember, if you discover anything that you would like to share, just message me, <a href="https://anaisurl.com/contact">I would love to hear from you.</a></p><p>Let’s get started ⛳</p><h3>Top Kubernetes Learning Resources 📖</h3><ul><li>Kubernetes has <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/">several interactive tutorials</a> on their Documentation</li></ul><p>Let’s stay on the practical resources, these websites provide great example projects to learn Kubernetes:</p><ul><li><a href="https://katacoda.com/courses/kubernetes">katacoda: Learn Kubernetes using Interactive Browser-Based Scenarios</a></li><li><a href="https://kubernetesbyexample.com/">Kubernetes by example</a>; by Red Hat OpenShift</li></ul><h3>Videos🎥</h3><p>Under the theme “You can learn anything”, <a href="https://www.youtube.com/channel/UCb4mfRT5UWpjoUQRcIE2qOQ?sub_confirmation=1">I am currently doing #100DaysOfKubernetes</a>. If you enjoy this newsletter, chances are high that you would get lots of value from my current and upcoming videos. Have a look 😊</p><h3>Have a look at the full newsletter here: https://blog.anaisurl.com/12-devops-diary-computer-science-and-k8s-resources/</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4445dc735e01" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>