<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Calvine Otieno</title>
    <description>The latest articles on DEV Community by Calvine Otieno (@calvine).</description>
    <link>https://dev.to/calvine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F378078%2F1f168d90-9847-478b-8850-151df3aa5760.jpeg</url>
      <title>DEV Community: Calvine Otieno</title>
      <link>https://dev.to/calvine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/calvine"/>
    <language>en</language>
    <item>
      <title>Improving your CI/CD Pipeline: Helm Charts Security Scanning with Trivy and GitHub Actions</title>
      <dc:creator>Calvine Otieno</dc:creator>
      <pubDate>Fri, 02 Dec 2022 15:14:21 +0000</pubDate>
      <link>https://dev.to/aws-builders/improving-your-cicd-pipeline-helm-charts-security-scanning-with-trivy-and-github-actions-3315</link>
      <guid>https://dev.to/aws-builders/improving-your-cicd-pipeline-helm-charts-security-scanning-with-trivy-and-github-actions-3315</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk55odmd8utkgvd6juwpx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk55odmd8utkgvd6juwpx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally published by me on &lt;a href="https://medium.com/@calvineotieno010/improving-your-ci-cd-pipeline-helm-charts-security-scanning-with-trivy-and-github-actions-acc081df2c2d" rel="noopener noreferrer"&gt;&lt;strong&gt;Medium&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DevOps has gained momentum over the past few years and it’s continuing to grow each day. Many organizations small, medium or big embrace DevOps processes. The automation of manual processes in the software development life cycle and faster release of features to customers are some of the key roles that DevOps culture brings to any organisation.&lt;/p&gt;

&lt;p&gt;With growing automation and CI/CD tools in the market, security has become a major concern. The rise of &lt;a href="https://www.docker.com/resources/what-container/" rel="noopener noreferrer"&gt;&lt;strong&gt;Containers&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Infrastructure_as_code" rel="noopener noreferrer"&gt;&lt;strong&gt;IaC&lt;/strong&gt;&lt;/a&gt; has led to major security issues and hence the rise of &lt;a href="https://www.redhat.com/en/topics/devops/what-is-devsecops" rel="noopener noreferrer"&gt;&lt;strong&gt;DevSecOps&lt;/strong&gt;&lt;/a&gt;. &lt;strong&gt;DevSecOps&lt;/strong&gt; is a concept where DevOps is augmented with security best practices early in the life of the &lt;a href="https://en.wikipedia.org/wiki/Systems_development_life_cycle" rel="noopener noreferrer"&gt;&lt;strong&gt;Software Development Life Cycle&lt;/strong&gt;&lt;/a&gt; (SLDC). Scanning the resultant artefacts be it docker images or Helm Charts for vulnerabilities is an essential part of that life cycle, especially for cloud-native environments.&lt;/p&gt;

&lt;p&gt;In this article, I will demo how we can perform automated vulnerability scans for Helm Charts using &lt;a href="https://docs.github.com/en/actions" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub Actions&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://github.com/aquasecurity/trivy" rel="noopener noreferrer"&gt;&lt;strong&gt;Trivy&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F47ktow2v6eiw22lxra1k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F47ktow2v6eiw22lxra1k.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trivy and Github Actions Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Trivy?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Trivy is an open-source project by Aqua Security. It’s a vulnerability/misconfiguration scanner for artefacts like container images, filesystems/rootfs, Helm Charts, and git repositories. It has a comprehensive detection for OS and language-specific packages, as well as Infrastructure as code files like Terraform. With Trivy, you can integrate this scanning with your CI/CD platform before you publish/deploy the artefacts to production.&lt;/p&gt;

&lt;p&gt;Trivy supports table, json, and sarif outputs formats. Sarif scan output can be written to the GitHub repo Security tab(for private repositories, you need Github advanced license).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to have some basic knowledge of working with Helm Charts and GitHub Actions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Helm Charts installed in your local machine&lt;/li&gt;
&lt;li&gt;Trivy installed in your local machine&lt;/li&gt;
&lt;li&gt;A public GitHub Repository&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And of course a code editor of your choice 😀.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s start&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a sample helm chart by running this command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm create sample-helm-devsecops
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will create a helm chart name sample-helm-devsecops.&lt;/p&gt;

&lt;p&gt;For the sake of this quick demo, we will be concentrating much on deployment.yaml file.&lt;/p&gt;

&lt;p&gt;Create a new folder name chart and move the sample-helm-devsecops folder and its content there.&lt;/p&gt;

&lt;p&gt;Let us do a trivy scan of our just created chart by running this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;trivy config charts/sample-helm-devsecops
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3qk55ume8q1wgxe8jqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3qk55ume8q1wgxe8jqh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;**Here we have Tests: 79 (SUCCESSES: 67, FAILURES: 12, EXCEPTIONS: 0)&lt;/p&gt;

&lt;p&gt;Failures: 12 (UNKNOWN: 0, LOW: 10, MEDIUM: 2, HIGH: 0, CRITICAL: 0)**&lt;/p&gt;

&lt;p&gt;Nice. We are done with our first step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create A GitHub Repo and Github Action&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have the chart set up, we can go ahead and push it to our &lt;strong&gt;GitHub repository&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Go ahead to your GitHub and create a &lt;a href="https://github.com/new" rel="noopener noreferrer"&gt;repository&lt;/a&gt;, here I called mine sample-helm-devsecops. I will assume you know how to add a remote origin and push your code. This article will not cover Git and GitHub fundamentals.&lt;/p&gt;

&lt;p&gt;After pushing your chart, let us create a workflow that will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run Trivy vulnerability scanner in IaC mode&lt;/li&gt;
&lt;li&gt;Upload Trivy scan results to the GitHub Security tab&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create a folder named .&lt;strong&gt;github&lt;/strong&gt; and inside it add another folder &lt;strong&gt;workflows&lt;/strong&gt;. In the workflows folder, create a file &lt;code&gt;trivy-secops.yaml&lt;/code&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;trivy-security-scanning&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;push&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;security-events&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt; &lt;span class="c1"&gt;# To upload sarif files&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;chart-test&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8&lt;/span&gt; &lt;span class="c1"&gt;# tag=v3.1.0&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;fetch-depth&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up Helm&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;azure/setup-helm@f382f75448129b3be48f8121b9857be18d815a82&lt;/span&gt; &lt;span class="c1"&gt;# tag=v3.4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v3.6.3&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up python&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-python@13ae5bb136fac2878aff31522b9efb785519f984&lt;/span&gt; &lt;span class="c1"&gt;# tag=v4.3.0&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;python-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3.7&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run Trivy vulnerability scanner in IaC mode&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;aquasecurity/trivy-action@9ab158e8597f3b310480b9a69402b419bc03dbd5&lt;/span&gt; &lt;span class="c1"&gt;# tag=0.8.0&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;scan-type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;config'&lt;/span&gt;
          &lt;span class="na"&gt;hide-progress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
          &lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sarif'&lt;/span&gt;
          &lt;span class="na"&gt;scan-ref&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;charts/sample-helm-devsecops'&lt;/span&gt;
          &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;trivy-results.sarif'&lt;/span&gt;
          &lt;span class="na"&gt;exit-code&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;1'&lt;/span&gt;
          &lt;span class="na"&gt;ignore-unfixed&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Upload Trivy scan results to GitHub Security tab&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github/codeql-action/upload-sarif@312e093a1892bd801f026f1090904ee8e460b9b6&lt;/span&gt; &lt;span class="c1"&gt;# v2.1.34&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;sarif_file&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;trivy-results.sarif'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are doing all the severity-level scans (&lt;strong&gt;LOW&lt;/strong&gt;, &lt;strong&gt;MEDIUM&lt;/strong&gt;, &lt;strong&gt;HIGH&lt;/strong&gt;, and &lt;strong&gt;CRITICAL&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add&lt;/code&gt; and &lt;code&gt;push&lt;/code&gt; the changes to GitHub. Check the Actions tab and you should see a workflow running. It will fail because of the vulnerabilities we saw earlier.&lt;/p&gt;

&lt;p&gt;Now go to the Security Tab and then click the Code scanning tab, you should see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxikikwnwddph7tpxfx4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxikikwnwddph7tpxfx4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see Trivy scanned our helm chart and uploaded the scan to Github Security Tab. From here we can create issues for these vulnerability scans and assign them to developers. Once the issue is fixed and the changes pushed, Trivy will run the scan again and the issue will be closed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo: Create an issue for vulnerability number #1 — Process can elevate its own privileges&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click the issue and it should take you to a new window giving a description of the severity. There you can create a GitHub issue and it will automatically link the vulnerability with the issue. This helps you to track the vulnerability and automatically close them with a &lt;a href="https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue" rel="noopener noreferrer"&gt;PR&lt;/a&gt; fixing the issue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Create a GitHub Issue for the vulnerability&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl644ip1arij7u599hzev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl644ip1arij7u599hzev.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5dqadmviyy4en10mmwfn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5dqadmviyy4en10mmwfn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we merge the PR, the issue should be closed and vulnerability #1 should be solved.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqzp3kvuirv3mpz11i5ok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqzp3kvuirv3mpz11i5ok.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see the issue has been resolved and in our recent scan it’s not there.&lt;/p&gt;

&lt;p&gt;You can now repeat these steps to fix the remaining issues and once done, your scan results should be clean.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rz1kllob9ckj0pu5ukp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rz1kllob9ckj0pu5ukp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is all for now. I hope you have learnt something and enjoyed reading the article. Next article we will focus on doing the same with &lt;a href="https://docs.gitlab.com/ee/ci/" rel="noopener noreferrer"&gt;Gitlab CI&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://github.com/NYARAS/sample-helm-devsecops" rel="noopener noreferrer"&gt;repo&lt;/a&gt; for this article. Follow me on &lt;a href="https://github.com/NYARAS" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; for more about DevOps and DevSecOps.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Let’s connect on &lt;a href="https://twitter.com/CalvineNyaranga" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/calvine-otieno-0259a813b/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; 😁.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>sre</category>
      <category>security</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Multi-Container Pod Design Patterns in Kubernetes — Sidecar Pattern</title>
      <dc:creator>Calvine Otieno</dc:creator>
      <pubDate>Tue, 22 Nov 2022 12:57:21 +0000</pubDate>
      <link>https://dev.to/aws-builders/multi-container-pod-design-patterns-in-kubernetes-sidecar-pattern-ook</link>
      <guid>https://dev.to/aws-builders/multi-container-pod-design-patterns-in-kubernetes-sidecar-pattern-ook</guid>
      <description>&lt;p&gt;Kubernetes is an open-source major player container orchestration engine for automating deployments, scaling and management of containerized applications.&lt;/p&gt;

&lt;p&gt;A pod is the basic building block of the kubernetes application. Pods encapsulate containers. A pod may have one or more containers, storage, IP Addresses and some other options that govern how containers should run inside the pod.&lt;/p&gt;

&lt;p&gt;A pod that has one container is called a single-container pod. It’s the most common kubernetes use case. A pod that has multiple co-related containers is called a multi-container pod. You don’t always need multi-container pods. When do you need to use them is the question. Some of the cases where you may need to use them are:&lt;/p&gt;

&lt;p&gt;When the containers have the exact lifecycle or when the containers must run on the same node. A scenario where you have a helper process that needs to be located and managed on the same node as the primary container.&lt;br&gt;
For simpler communication between containers in the pod. These containers can communicate through shared volumes (writing to a shared file or directory) and through inter-process communication (semaphores or shared memory) When the containers have the exact same lifecycle, or when the containers must run on the same node. The most common scenario is that you have a helper process that needs to be located and managed on the same node as the primary container.&lt;br&gt;
There are three common design patterns and use cases for combining multiple containers into a single pod:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sidecar pattern&lt;/strong&gt; (This article)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adapter pattern&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ambassador pattern&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sidecar Pattern&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This pattern consists of a main application i.e. a web application plus a helper container with a responsibility that is essential to the web application but it’s not necessarily part of the application itself. The common sidecar containers are logging utilities, sync services, watchers, and monitoring agents. It does not make sense if a logging container is running while the application itself isn’t running, so we create a multi-container pod that has the main application and the sidecar container (logging container in this case).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
Let's deploy a simple pod to understand this pattern. A pod that has primary and sidecar containers.&lt;/p&gt;

&lt;p&gt;The main container is a simple Nginx application serving on port 80 that takes the index.html from the volume mount location. The Sidecar container uses a busybox image and writes the current date to a log file every five seconds. In practice, your sidecar is likely to be a log collection container that uploads to external storage.&lt;/p&gt;

&lt;p&gt;For you to apply this example, you need to install Minikube as a prerequisite Apply the manifest&lt;/p&gt;

&lt;p&gt;You can clone this repo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/NYARAS/k8s-sidecar-container-pattern" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apply the pod manifest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f sidecar-pod.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the pod is running, connect to the sidecar pod:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl exec -it  sidecar-container-example -c main-container -- /bin/sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install curl on the sidecar&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt-get update &amp;amp;&amp;amp; apt-get install -y curl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access the log file(index.html) via the sidecar&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl localhost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnpux9557njpmh3hlbrmr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnpux9557njpmh3hlbrmr.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally published by me on &lt;a href="https://medium.com/@calvineotieno010/multi-container-pod-design-patterns-in-kubernetes-sidecar-pattern-d2dad1f6e81b" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next article we will be talking about Adapter pattern. Until next time, thank you.&lt;/p&gt;

&lt;p&gt;That’s all for now. Thanks for reading. Let’s connect on Twitter and LinkedIn 😁.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>containerapps</category>
      <category>community</category>
    </item>
  </channel>
</rss>
