<?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 Esteban Aramendi on Medium]]></title>
        <description><![CDATA[Stories by Esteban Aramendi on Medium]]></description>
        <link>https://medium.com/@estebanaramendi?source=rss-405a30a2a48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K-L5oU7x3HbNTJsy73mHdg.jpeg</url>
            <title>Stories by Esteban Aramendi on Medium</title>
            <link>https://medium.com/@estebanaramendi?source=rss-405a30a2a48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:36:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@estebanaramendi/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[Streamline Kubernetes Security with Kyverno and Policy-as-Code]]></title>
            <link>https://medium.com/globant/streamline-kubernetes-security-with-kyverno-and-policy-as-code-ae1aaae25d7c?source=rss-405a30a2a48------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae1aaae25d7c</guid>
            <category><![CDATA[kyverno]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[cloudops]]></category>
            <category><![CDATA[policy-as-code]]></category>
            <category><![CDATA[kubernetes-security]]></category>
            <dc:creator><![CDATA[Esteban Aramendi]]></dc:creator>
            <pubDate>Wed, 07 May 2025 15:02:41 GMT</pubDate>
            <atom:updated>2025-05-07T15:02:41.820Z</atom:updated>
            <content:encoded><![CDATA[<h4>Improve Kubernetes security posture through policies, audits, and security reports.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EZQAniJe-VKNUGYSeer-qw.jpeg" /><figcaption>Source: <a href="https://plus.unsplash.com/premium_photo-1729321202012-f24e25d7e83f?q=80&amp;w=1932&amp;auto=format&amp;fit=crop&amp;ixlib=rb-4.0.3&amp;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">Unsplash</a></figcaption></figure><p><a href="https://kyverno.io/">Kyverno</a> is a tool maintained by the Cloud Native Computing Foundation (<a href="https://www.cncf.io/">CNCF</a>) project. It aims to provide a toolset for administering and managing Kubernetes (<a href="https://kubernetes.io/">K8s</a>) policies using the Policy-As-Code (<a href="https://www.paloaltonetworks.com/cyberpedia/what-is-policy-as-code">PaC</a>) lifecycle and simplifying it by leveraging resources declared in the <a href="https://yaml.org/">YAML</a> language.</p><p>This article describes how to install and declare a basic set of policies using Kyverno in a K8s environment, the Google Kubernetes Engine (<a href="https://cloud.google.com/kubernetes-engine?hl=en">GKE</a>) in a Google Cloud Project (<a href="https://cloud.google.com/">GCP</a>), and <a href="https://helm.sh/">Helm charts</a>.</p><blockquote><strong>Note: </strong>You can install it on any other cloud provider and even use <a href="https://minikube.sigs.k8s.io/docs/start/?arch=%2Fmacos%2Fx86-64%2Fstable%2Fbinary+download">minikube</a> and other installation methods that you can check <a href="https://kyverno.io/docs/installation/methods/">here</a>.</blockquote><h3>Prerequisites</h3><p>For you to follow these steps successfully, you will need to have prepared the following:</p><ul><li>A GCP Project.</li><li>Enable the Application Programming Interface (<a href="https://en.wikipedia.org/wiki/API">APIs</a>) related to Compute, Network and GKE.</li><li>A Virtual Private Cloud (<a href="https://cloud.google.com/vpc">VPC</a>) Network.</li><li>A GKE Cluster.</li><li>A Command Line Interface (<a href="https://en.wikipedia.org/wiki/Command-line_interface">CLI</a>) with the following tools installed <a href="https://cloud.google.com/sdk/docs/install">GCloud</a>, <a href="https://helm.sh/docs/intro/install/">Helm</a> and <a href="https://mikefarah.gitbook.io/yq/v3.x">yq</a>.</li></ul><p>If you need help creating such resources, you can use these links to create them using Terraform:</p><ul><li><a href="https://github.com/terraform-google-modules/terraform-google-kubernetes-engine">GitHub — terraform-google-modules/terraform-google-kubernetes-engine</a>: Configures opinionated GKE clusters.</li><li><a href="https://github.com/terraform-google-modules/terraform-google-project-factory">GitHub — terraform-google-modules/terraform-google-project-factory</a>: Creates an opinionated Google Cloud project by using Shared VPC, IAM, and Google Cloud APIs.</li></ul><p>Or use gcloud commands to create the GKE cluster. First, set the GCP project, computing zone, and region:</p><pre># Set default project<br>gcloud config set project [kyverno-poc]<br><br># Set default computer zone<br>gcloud config set compute/zone [us-east1]<br><br># Set default compute region/zone<br>gcloud config set compute/region [us-east1-b]<br></pre><p>Then, create a GKE cluster in the zone that you want. In this example, we are using us-east1-b, and we will use <a href="https://cloud.google.com/compute/docs/instances/spot">spot instances</a> to reduce costs:</p><pre>gcloud container clusters create kyverno-poc \<br>         --zone us-east1-b \<br>  --spot</pre><h3>Installation Steps</h3><p>We are going to use Kyverno’s <a href="https://kyverno.io/docs/installation/methods/#standalone-installation">standalone installation</a> method. For this, we will use <a href="https://helm.sh/">Helm</a> to download and install Kyverno. First, add the Kyverno Helm chart to your local machine and/or environment:</p><pre>helm repo add kyverno https://kyverno.github.io/kyverno/<br><br>&quot;kyverno&quot; has been added to your repositories</pre><p>Now, update the Kyverno Helm repository:</p><pre>helm repo update<br><br>Hang tight while we grab the latest from your chart repositories...<br>...Successfully got an update from the &quot;falcosecurity&quot; chart repository<br>...Successfully got an update from the &quot;kyverno&quot; chart repository<br>Update Complete. ⎈Happy Helming!⎈</pre><p>Lastly, install the Helm charts on your Kubernetes cluster and create a Kyverno namespace:</p><pre>helm install kyverno kyverno/kyverno -n kyverno --create-namespace<br><br>NAME: kyverno<br>LAST DEPLOYED: Mon Feb 24 10:42:45 2025<br>NAMESPACE: kyverno<br>STATUS: deployed<br>REVISION: 1<br>NOTES:<br>Chart version: 3.3.7<br>Kyverno version: v1.13.4<br><br>Thank you for installing kyverno! Your release is named kyverno.<br><br><br><br>The following components have been installed in your cluster:<br>- CRDs<br>- Admission controller<br>- Reports controller<br>- Cleanup controller<br>- Background controller<br><br><br>⚠️  WARNING: Setting the admission controller replica count below 2 means Kyverno is not running in high availability mode.<br><br><br>⚠️  WARNING: PolicyExceptions are disabled by default. To enable them, set &#39;--enablePolicyException&#39; to true.<br><br>💡 Note: There is a trade-off when deciding which approach to take regarding Namespace exclusions. Please see the documentation at https://kyverno.io/docs/installation/#security-vs-operability to understand the risks.</pre><p>After following these instructions, Kyverno will be installed in our cluster, and we can start using its policies.</p><blockquote><strong>NOTE: </strong>Following the <a href="https://kyverno.io/docs/installation/methods/#high-availability-installation">High-Availability installation</a> for production environments is highly recommended.</blockquote><h4>Policies</h4><p>Kyverno calls “policies” a collection of rules that consist of various objects declared <a href="https://kyverno.io/docs/kyverno-policies/">here</a>.</p><p>A policy can be defined either for cluster-wide or namespace-level resources, which will provide you with fine-grained security control of your objects in Kubernetes</p><p>Even more, you can have policies for:</p><ul><li><em>Exceptions</em>: an authorized object to be allowed to pass another preventive policy.</li><li><em>Cleanup</em>: designed to delete resources that match the policy rules.</li></ul><p>At the same time, you can use already written and curated policies by the community that can be found <a href="https://kyverno.io/policies/">here</a>. If your environment requires customized configurations, you can write your own policies. Usually, this will not be the case, but if needed, you can pre-evaluate the policy execution results by leveraging the use of <a href="https://playground.kyverno.io/#/">Kyverno Playground</a>, which emulates the result of a policy against your Kubernetes resource configuration.</p><p>As mentioned before, a policy will contain several rules. Each rule has a match evaluation and, optionally, an exclude section. The rule can contain other Kyverno objects such as Validate, Mutate, Generate, and Verify Images. In the picture below, you can find a hierarchy diagram of policy content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*He-DRvQFeraC8bSV" /><figcaption>Policy image — Resources that form a policy.</figcaption></figure><p>We will start by leveraging an already existing and curated set of policies, Kubernetes Pod Security Standards (<a href="https://kubernetes.io/docs/concepts/security/pod-security-standards/">PSS</a>). We will use Helm again, as documented <a href="https://github.com/kyverno/kyverno/tree/main/charts/kyverno-policies">here</a>:</p><pre>helm install kyverno-policies --namespace kyverno kyverno/kyverno-policies<br><br>NAME: kyverno-policies<br>LAST DEPLOYED: Mon Feb 24 10:49:35 2025<br>NAMESPACE: kyverno<br>STATUS: deployed<br>REVISION: 1<br>TEST SUITE: None<br>NOTES:<br>Thank you for installing kyverno-policies 3.3.4 😀</pre><p>We have installed the “baseline” profile of Pod Security Standards and set it in Audit mode. You can find more sample policies <a href="https://kyverno.io/policies/">here</a>. Now, let’s retrieve Kyverno pods status:</p><pre>kubectl get pods -n kyverno<br>NAME                                         READY   STATUS RESTARTS   AGE<br>kyverno-admission-controller-df7b67cf-526vw  1/1  Running   0       7m5s<br>kyverno-background-controller-8544847cf-psmst1/1  Running   0       7m5s<br>kyverno-cleanup-controller-5db46d8ddb-h2vfd  1/1  Running   0       7m5s<br>kyverno-reports-controller-77f95686d4-sfmxx  1/1  Running   0       7m5s</pre><p>This out-of-the-box Kyverno Helm installation will give you two policy categories: Baseline and Restricted. The latter aggregates both the baseline plus a more restrictive set of policies. The following is the complete list:</p><p><strong>Baseline</strong></p><ul><li>disallow-capabilities</li><li>disallow-host-namespaces</li><li>disallow-host-path</li><li>disallow-host-ports</li><li>disallow-host-process</li><li>disallow-privileged-containers</li><li>disallow-proc-mount</li><li>disallow-selinux</li><li>restrict-apparmor-profiles</li><li>restrict-seccomp</li><li>restrict-sysctls</li></ul><p><strong>Restricted</strong></p><ul><li>disallow-capabilities-strict</li><li>disallow-privilege-escalation</li><li>require-run-as-non-root-user</li><li>require-run-as-nonroot</li><li>restrict-seccomp-strict</li><li>restrict-volume-types</li></ul><p>You can inspect these and other policies in <a href="https://kyverno.io/policies/?policytypes=Mesh%2BPod%2520Security%2520Standards%2520%28Restricted%29">this document</a>. The policies have two types of failure actions whenever a policy is not met:</p><ul><li><em>Audit</em>: Audit report that there is an object in the cluster not complying with the Kyverno policy.</li><li><em>Enforce</em>: Enforce will prevent the object from being created in the cluster, resulting in an error when trying to execute the action in the cluster.</li></ul><p>You can inspect the result of the installed policies in the cluster by using the following command:</p><pre>kubectl get policyreport -n kube-system<br><br>NAMESPACE      NAME                                KIND       NAME                                                 PASS   FAIL   WARN   ERROR   SKIP   AGE<br>kube-system    c585987e-abfa-41c5-a5b9-4820465efc03   Deployment event-exporter-gke                                   11  1   0   0    0   95s</pre><blockquote><strong>Note: </strong>The following output was trimmed to highlight the next steps</blockquote><p>The following command can be used to know why a policy failed:</p><pre>kubectl get polr c585987e-abfa-41c5-a5b9-4820465efc03 -n kube-system -o jsonpath=&#39;{.results[?()]}&#39; | yq -p json<br>category: Pod Security Standards (Baseline)<br>message: validation rule &#39;autogen-adding-capabilities&#39; passed.<br>policy: disallow-capabilities<br>result: pass<br>rule: autogen-adding-capabilities<br>scored: true<br>severity: medium<br>source: kyverno<br>timestamp:<br>  nanos: 0<br>  seconds: 1740394210<br>---<br>category: Pod Security Standards (Baseline)<br>message: &#39;validation error: HostPath volumes are forbidden. The field spec.volumes[*].hostPath must be unset. rule autogen-host-path failed at path /spec/template/spec/volumes/0/hostPath/&#39;<br>policy: disallow-host-path<br>result: fail<br>rule: autogen-host-path<br>scored: true<br>severity: medium<br>source: kyverno<br>timestamp:<br>  nanos: 0<br>  seconds: 1740394210<br>---<br>[...]</pre><p>From that output, the only policy with result: fail that we see is the following:</p><pre>category: Pod Security Standards (Baseline)<br>message: &#39;validation error: HostPath volumes are forbidden. The field spec.volumes[*].hostPath must be unset. rule autogen-host-path failed at path /spec/template/spec/volumes/0/hostPath/&#39;<br>policy: disallow-host-path<br>result: fail<br>rule: autogen-host-path<br>scored: true<br>severity: medium<br>source: kyverno<br>timestamp:<br>  nanos: 0<br>  seconds: 1740394210</pre><p>We can see that the policy that failed was the disallow-host-path, with which we can inspect the <a href="https://kubernetes.io/docs/concepts/security/pod-security-standards/">Pod Security Standards (PSS) document</a> to see that our deployment is failing because we are using a HostPath volume, which must be forbidden. Now, in this other example:</p><pre>---<br>category: Pod Security Standards (Baseline)<br>message: &#39;validation error: Privileged mode is disallowed. The fields spec.containers[*].securityContext.privileged and spec.initContainers[*].securityContext.privileged must be unset or set to `false`. rule privileged-containers failed at path /spec/containers/0/securityContext/privileged/&#39;<br>policy: disallow-privileged-containers<br>result: fail<br>rule: privileged-containers<br>scored: true<br>severity: medium<br>source: kyverno<br>timestamp:<br>  nanos: 0<br>  seconds: 1740394212<br>—</pre><p>We can see that the rule for privileged containers has not been met and that neither the containers nor the initContainer spec has been set to true the privileged parameter.</p><p>Here, we can take two paths:</p><ul><li>We can create a <a href="https://kyverno.io/docs/writing-policies/exceptions/">policy exception</a> for that rule by using its namespace, resource name, etc.</li><li>We need to adjust our deployment so that it does not have a HostPath volume.</li></ul><p>This is where you will dwell most of the time managing Kyverno, whether the policy should fit the application or the application should fit the policy.</p><p>Every policy should be analyzed carefully, as every resource and application needs to fit a particular set of characteristics, but thanks to Kyverno, you can make that simpler by using its already predefined set of policies and exceptions. In case you have to take a more customizable approach, you can make use of <a href="https://kyverno.io/docs/writing-policies/">writing your own policies</a></p><h3>Conclusion</h3><p>Kyverno is a tool designed to help you secure your Kubernetes workloads by following rigorous, curated, and community-developed policies that are ready to fit the vast majority of use cases that you may encounter. Furthermore, if you require full control over your policies, Kyverno allows you to create custom policies.</p><p>Kyverno’s reporting features will enable you to understand your security posture quickly, allowing teams to proactively identify and address potential vulnerabilities. Additionally, with the ability to integrate it with tools such as Prometheus and Grafana, you will have full visibility on how to build a safer Kubernetes environment, empowering you to build a safer infrastructure.</p><h3>Further Reading</h3><ul><li><a href="https://kyverno.io/policies/">Policies | Kyverno</a></li><li><a href="https://kyverno.io/docs/policy-reports/">Reporting | Kyverno</a></li><li><a href="https://kyverno.io/docs/monitoring">Monitoring | Kyverno</a></li><li><a href="https://playground.kyverno.io/">Kyverno Playground</a></li><li><a href="https://kubernetes.io/docs/concepts/security/pod-security-standards/">Pod Security Standards | Kubernetes</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae1aaae25d7c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/globant/streamline-kubernetes-security-with-kyverno-and-policy-as-code-ae1aaae25d7c">Streamline Kubernetes Security with Kyverno and Policy-as-Code</a> was originally published in <a href="https://medium.com/globant">Globant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infrastructure as Code using Kubernetes]]></title>
            <link>https://medium.com/globant/infrastructure-as-code-using-kubernetes-d3d329446517?source=rss-405a30a2a48------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3d329446517</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[config-connector]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Esteban Aramendi]]></dc:creator>
            <pubDate>Tue, 14 Feb 2023 12:44:54 GMT</pubDate>
            <atom:updated>2023-02-14T12:44:54.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bIC6NsC9s4KJ2qCS" /><figcaption>Photo by <a href="https://unsplash.com/@ivanchenao?utm_source=medium&amp;utm_medium=referral">Ivan Henao</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://cloud.google.com/config-connector/docs/overview">Config Connector</a> (KCC) is a solution to maintain Cloud Resources as Infrastructure as Code. It is built as an <a href="https://opensource.org/">Open Source initiative</a> and runs on <a href="https://kubernetes.io/">Kubernetes</a> clusters. As such, it leverages <a href="https://yaml.org/">YAML files</a> to maintain and operate such resources.</p><p>Config Connector has two versions: an Add-On for Google Kubernetes Engine (<a href="https://cloud.google.com/kubernetes-engine">GKE</a>) clusters and a manual installation for other Kubernetes distributions.</p><p>The purpose of this article is to install <a href="https://cloud.google.com/config-connector/docs/how-to/install-upgrade-uninstall">ConfigConnector as an Add-On</a> and create and import resources to manage your infrastructure from one place.</p><p>This article will be helpful to any Cloud or DevOps engineer at any level. Knowledge of Google Cloud and the &quot;Infrastructure As Code&quot; process will be needed.</p><h3><strong>Prerequisites</strong></h3><p>For you to follow these steps successfully, you will need the following:</p><ul><li>A Google Cloud Project (<a href="https://cloud.google.com/">GCP</a>) in which we will install Config Connector and deploy your resources.</li><li>An enabled Application Programming Interface (<a href="https://en.wikipedia.org/wiki/API">API</a>) related to Compute, Network, GKE, and Cloud Resource Manager to be able to create the resources.</li><li>A Virtual Private Cloud (<a href="https://cloud.google.com/vpc">VPC</a>) Network, used as a resource creation example.</li><li>A Google Kubernetes Engine (<a href="https://cloud.google.com/kubernetes-engine">GKE</a>) Cluster where Config Connector will run.</li></ul><blockquote><strong>Note: </strong>KCC needs CloudResource API enabled to work properly therefore you will need to enable it before starting to deploy resources. You can use the command below to do so.</blockquote><pre>gcloud services enable cloudresourcemanager.googleapis.com</pre><p>If you need help creating such resources, you can use these links:</p><ul><li><a href="https://github.com/terraform-google-modules/terraform-google-kubernetes-engine">https://github.com/terraform-google-modules/terraform-google-kubernetes-engine</a></li><li><a href="https://github.com/terraform-google-modules/terraform-google-project-factory">https://github.com/terraform-google-modules/terraform-google-project-factory</a></li></ul><p>You could also use the following gcloudcommands:</p><pre># Set default project<br>gcloud config set project [iac-configconnector]<br><br># Set default computer zone<br>gcloud config set compute/zone [us-east1]<br><br># Set default compute region/zone<br>gcloud config set compute/region [us-east1-b]<br><br># Create a GKE cluster<br>gcloud container clusters create configconnectordeplyments\<br>      --zone us-east1-b</pre><p><strong><em>Note: </em></strong><em>If you are testing it, you can add the </em><em>--spot flag to the last command to reduce costs.</em></p><p>The expected output of the last command should be similar to the following:</p><pre>NAME: configconnectordeplyments<br>LOCATION: us-east1-b<br>MASTER_VERSION: 1.24.8-gke.2000<br>MASTER_IP: 34.139.195.104<br>MACHINE_TYPE: e2-medium<br>NODE_VERSION: 1.24.8-gke.2000<br>NUM_NODES: 3<br>STATUS: RUNNING</pre><h3><strong>Installation steps</strong></h3><p>We need to create a Google service account that will be used as the deployer of all the resources in the GCP project, folder, or organization.</p><pre>gcloud iam service-accounts create conf-connect</pre><p>Once created, we will add the Owner role in the respective scope of the cluster.</p><pre>gcloud projects add-iam-policy-binding iac-configconnector  \<br>--member serviceAccount:conf-connect@iac-configconnector.iam.gserviceaccount.com  \<br>--role roles/ownerbas</pre><p><strong><em>Note:</em></strong><em> Assigning Owner or predefined roles is rarely the case and not a best practice: it will surely grant more access than needed. This is only for testing purposes. For productive or more formal environments, please create a custom role containing all of the permissions of the resources you will create through Config Connector.</em></p><p>We will create two namespaces, one for the KCC workloads and another one for resource references ( configconnect-ns as an example).</p><pre>kubectl create namespace cnrm-system (for KCC)<br>kubectl create namespace configconnect-ns (example)</pre><p>Create a key for the previously created Google Service Account and store it in a key.json file.</p><pre>gcloud iam service-accounts keys create --iam-account \<br>conf-connect@iac-configconnector.iam.gserviceaccount.com key.json</pre><p><strong><em>Note:</em></strong><em> Again, this should be avoided in formal or productive environments. For such scenarios,, please refer to the following documentation for a better approach.</em></p><p><a href="https://cloud.google.com/secret-manager/docs/using-other-products#google-kubernetes-engine">Use Secret Manager with other products | Secret Manager Documentation | Google Cloud</a></p><p><a href="https://cloud.google.com/config-connector/docs/how-to/advanced-install#installing_the_operator">Download the config connector bundle package:</a></p><pre>gsutil cp gs://cnrm/latest/release-bundle.tar.gz release-bundle.tar.gz</pre><p>Untar the file.</p><pre>tar -xvf release-bundle.tar.gz</pre><p>Install config connector bundle:</p><pre>kubectl apply -f install-bundle-gcp-identity/</pre><p><a href="https://cloud.google.com/config-connector/docs/how-to/import-export/overview#installing_config-connector">Install Config Connector CLI Toolkit to import and export resources.</a></p><p>Now you need to set the scope of the Config connector cluster. Choose one of the following three cases that apply to your use case. For our example, we will select # Project:</p><pre># Folder:<br>kubectl annotate namespace \<br>configconnect-ns cnrm.cloud.google.com/folder-id=[FOLDER_ID]<br><br># Project (We will use this one for the demo):<br>kubectl annotate namespace \<br>configconnect-ns cnrm.cloud.google.com/project-id=iac-configconnector<br><br># Organization:<br>kubectl annotate namespace \<br>configconnect-ns cnrm.cloud.google.com/organization-id=[ORGANIZATION_ID]</pre><p>Config the namespace delegated to a default namespace: this avoids the use of the --namespace<em> </em>parameter in every kubectlcommand ( configconnect-ns for this example):</p><pre>kubectl config set-context --current --namespace configconnect-ns</pre><h3><strong>Connection to the KCC Cluster</strong></h3><p>To connect to an existing KCC cluster, you will need to add this cluster to your local kubeconfig file. Please check the process in <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl">this document</a>.</p><p>You can list all the resources available to be deployed/managed by KCC using this command:</p><pre>kubectl get crds --selector cnrm.cloud.google.com/managed-by-kcc=true</pre><p>Or by checking the following <a href="https://cloud.google.com/config-connector/docs/reference/overview">documentation</a>.</p><p>Using this URL, you can check the YAML structure and parameters needed for every service deployed through KCC.</p><p>You could check this also using this command (compute subnetwork as an example):</p><pre>kubectl describe crd computesubnetworks.compute.cnrm.cloud.google.comb</pre><p>You can get the Name of the resource performing the previous command.</p><pre>kubectl get crds --selector cnrm.cloud.google.com/managed-by-kcc=true</pre><p>After you decide the kind of resource(s) that will be deployed, then you need to enable the API related to each resource to be deployed in case of being disabled; this action could be performed with gcloud commands in the Console or using a YAML through KCC.</p><p>The YAML template to enable an API is:</p><pre>apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1<br>kind: Service<br>metadata:<br>  name: networkmanagement.googleapis.com // this service as an example</pre><p>Following the example of the networking resource case, a YAML structure for VPC creation and subnetwork (a single YAML could be used to deploy more than one resource) looks like this:</p><pre>apiVersion: compute.cnrm.cloud.google.com/v1beta1<br>kind: ComputeNetwork<br>metadata:<br> name: kccproject-op<br>spec:<br> routingMode: REGIONAL<br> autoCreateSubnetworks: false <br>---<br>apiVersion: compute.cnrm.cloud.google.com/v1beta1<br>kind: ComputeSubnetwork<br>metadata:<br> labels:<br>   label-one: &quot;cloudbuild&quot;<br> name: subnetwork-vm<br>spec:<br> ipCidrRange: 10.100.10.0/24<br> region: us-east1<br> description: IaC subnet for Instances<br> privateIpGoogleAccess: false<br> networkRef:<br>   name: kccproject-op<br> logConfig:<br>   aggregationInterval: INTERVAL_15_MIN<br>   flowSampling: 0.5<br>   metadata: INCLUDE_ALL_METADATA</pre><p>The command to deploy the GCP resource is the following:</p><pre>kubectl apply -f create_network.yaml</pre><blockquote><strong>Note: </strong>create_network.yaml is the file where you will have the code to create your resources in YAML language. You can name this file as you see fit.</blockquote><p>To check a deployment status or some error, you can use this command to review the logs in the Controller manager workload:</p><pre>kubectl logs cnrm-controller-manager-0 --namespace=cnrm-system</pre><p>The expected output should be similar to the following:</p><pre>my-user@cloudshell:~/.kcc: my-project$ kubectl logs cnrm-controller-manager --namespace=cnrm-system | tail -10<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;reference ComputeNetwork configconnect-ns/kccproject-np is not ready&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;]}<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;starting reconcile&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;]}<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;reference ComputeNetwork configconnect-ns/kccproject-np is not ready&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;]}<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;successfully finished reconcile&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;}]<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;starting reconcile&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;]}<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;creating/updating underlying resource&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;]}<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;successfully finished reconcile&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;}]<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;starting reconcile&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;]}<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;underlying resource up to date&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;]}<br>{&quot;level&quot;:&quot;info&quot;:&quot;ts&quot;:[REDACTED],&quot;logger&quot;:&quot;computesubnetwork-controller&quot;,&quot;msg&quot;:&quot;successfully finished reconcile&quot;,&quot;resource&quot;:[&quot;namespace&quot;:&quot;configconnect-ns&quot;,&quot;name&quot;:&quot;subnetwork-vm&quot;}]</pre><p>And then you can also check in the Console:</p><ul><li>Click on the &quot;Navigation Menu&quot;.</li><li>Select &quot;VPC Network&quot;.</li><li>And now you will have a new VPC network called &quot;kccproject-op&quot; with a subnetwork associated with it called &quot;subnetwork-vm,&quot; where both of them have been created from KCC.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wrbIJJhJK6MbWA6_" /><figcaption>Resource creation example.</figcaption></figure><p>If you need to delete a resource, you need to specify the YAML associated with this in the creation process using the command.</p><pre>kubectl delete -f &lt;file_name&gt;.yaml</pre><h3><strong>Listing managed objects by KCC</strong></h3><p>In the GKE cluster section, you can go to Object Browser, and there you will be able to see the objects managed by KCC alongside with the object properties, and you will even have the option to download a YAML file with the configuration for that resource.</p><p>And then you can also check in the Console:</p><ul><li>Click on the &quot;Navigation Menu&quot;.</li><li>Select &quot;Kubernetes Engine&quot;.</li><li>Select &quot;Object Browser&quot;.</li><li>And there you will see the objects that KCC has created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fShXlxzSMcjMd1QY" /><figcaption>Listing resources example.</figcaption></figure><h3><strong>Importing existing resources into KCC</strong></h3><p>For this scenario, we will create a bucket from the GCP Console. After its creation, we will execute the following command that will export all bucket objects into a YAML file.</p><pre>bucket_name = my_bucket_$RANDOM<br>gcloud asset export  --content-type resource  --project kubeconfig-test-poc  --asset-types storage.googleapis.com/Bucket  --output-path &quot;gs://$bucket_name/my_objects.json&quot;</pre><p>We will download the file exported from the previous command.</p><pre>gsutil cp gs://$bucket_name/my_objects.json .</pre><p>And now, by using the config-connector toolkit, we will import it.</p><pre>config-connector bulk-export -i ./my_objects.json</pre><p>And with this, you can now obtain the JSON file to import it into KCC.</p><pre>apiVersion: storage.cnrm.cloud.google.com/v1beta1<br>kind: StorageBucket<br>metadata:<br>  annotations:<br>    cnrm.cloud.google.com/force-destroy: &quot;false&quot;<br>    cnrm.cloud.google.com/project-id: REDACTED<br>  name: kubeconfig-test-poc-bucket-outside-config-123sad<br>spec:<br>  location: US-EAST1<br>  publicAccessPrevention: enforced<br>  resourceID: kubeconfig-test-poc-bucket-outside-config-123sad<br>  storageClass: STANDARD<br>  uniformBucketLevelAccess: true<br>---<br>apiVersion: iam.cnrm.cloud.google.com/v1beta1<br>kind: IAMPolicy<br>metadata:<br>  name: kubeconfig-test-poc-bucket-outside-config-123sad-iampolicy<br>spec:<br>  bindings:<br>  - members:<br>    - projectEditor:REDACTED<br>    - projectOwner:REDACTED<br>    role: roles/storage.legacyBucketOwner<br>  - members:<br>    - projectViewer:REDACTED<br>    role: roles/storage.legacyBucketReader<br>  - members:<br>    - projectEditor:REDACTED<br>    - projectOwner:REDACTED<br>    role: roles/storage.legacyObjectOwner<br>  - members:<br>    - projectViewer:REDACTED<br>    role: roles/storage.legacyObjectReader<br>  resourceRef:<br>    apiVersion: storage.cnrm.cloud.google.com/v1beta1<br>    external: kubeconfig-test-poc-bucket-outside-config-123sad<br>    kind: StorageBucket<br>---<br>apiVersion: storage.cnrm.cloud.google.com/v1beta1<br>kind: StorageBucket<br>metadata:<br>  annotations:<br>    cnrm.cloud.google.com/force-destroy: &quot;false&quot;<br>    cnrm.cloud.google.com/project-id: REDACTED<br>  labels:<br>    managed-by-cnrm: &quot;true&quot;<br>  name: kubeconfig-test-poc-bucket-df82763sa<br>spec:<br>  lifecycleRule:<br>  - action:<br>      storageClass: NEARLINE<br>      type: SetStorageClass<br>    condition:<br>      age: 30<br>      withState: ANY<br>  location: US<br>  publicAccessPrevention: inherited<br>  resourceID: kubeconfig-test-poc-bucket-df82763sa<br>  storageClass: STANDARD<br>  uniformBucketLevelAccess: true<br>  versioning:<br>    enabled: false<br>---<br>apiVersion: iam.cnrm.cloud.google.com/v1beta1<br>kind: IAMPolicy<br>metadata:<br>  name: kubeconfig-test-poc-bucket-df82763sa-iampolicy<br>spec:<br>  bindings:<br>  - members:<br>    - projectEditor:REDACTED<br>    - projectOwner:REDACTED<br>    - user:REDACTED<br>    role: roles/storage.legacyBucketOwner<br>  - members:<br>    - projectViewer:kubeconfig-test-poc<br>    role: roles/storage.legacyBucketReader<br>  - members:<br>    - projectEditor:REDACTED<br>    - projectOwner:REDACTED<br>    role: roles/storage.legacyObjectOwner<br>  - members:<br>    - projectViewer:REDACTED<br>    role: roles/storage.legacyObjectReader<br>  resourceRef:<br>    apiVersion: storage.cnrm.cloud.google.com/v1beta1<br>    external: kubeconfig-test-poc-bucket-df82763sa<br>    kind: StorageBucket</pre><p>You can save this information in a YAML file and import it using the command.</p><pre>kubectl apply -f bucket-outside.yaml</pre><pre>storagebucket.storage.cnzm.cloud.google.com/config-export-buckeet created <br>iampolicy.iam.cnrm.cloud.google.com/config-export-buckeet-iampolicy created <br>storagebucket.storage.cnrm.cloud.google.com/dato8984akd created<br>iampolicy.iam.cnrm.cloud.google.com/dafo8984skd-iampolicy created</pre><p>Instead of importing one bucket at a time, you can import all the existing buckets using their resource type.</p><p>By using gcloud asset export let&#39;s make an export of the asset types for the bucket.</p><pre>gcloud asset export  --content-type resource  --project &lt;project-id&gt;  --asset-types storage.googleapis.com/Bucket  --output-path &quot;gs://$bucket_name/my_objects.yaml&quot; --format=yaml</pre><p>Copy it to your pwd .</p><pre>gsutil cp gs://$bucket_name/my_objects.yaml .</pre><p>Change the file from YAML to JSON.</p><pre>mv my_objects.yaml my_objects.json</pre><p>And by using both tools, config-connector and kubectl import it to your configuration.</p><pre>config-connector bulk-export -i ./my_objects.json | kubectl apply -f -<br><br>[redacted]cloudshell:-/linux/amd64[redacted]$ ./config-connector bulk-export -i ./my_file.json | kubectl apply -f -<br>storagebucket.storage.cnzm.cloud.google.com/config-export-buckeet created iampolicy.iam.cnrm.cloud.google.com/config-export-buckeet-iampolicy created storagebucket.storage.cnrm.cloud.google.com/dato8984akd created<br>iampolicy.iam.cnrm.cloud.google.com/dafo8984skd-iampolicy created</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MnwOB-YPQQd70Z0d" /><figcaption>Config Connector sample diagram/workflow.</figcaption></figure><h3><strong>Conclusion</strong></h3><p>Following this post, you can install Config Connector in your GKE Cluster. Afterward, you will manage resources and import existing ones into KCC, and to do so, you will be using YAML files and the K8s command line.</p><h3>Further Reading</h3><p><a href="https://cloud.google.com/config-connector/docs/overview">Google Cloud Config Connector Overview</a>.<br><a href="https://cloud.google.com/config-connector/docs/how-to/import-export/export">How to import and export resources documentation.<br></a><a href="https://cloud.google.com/config-connector/docs/how-to/import-export/bulk-exporthttps://cloud.google.com/config-connector/docs/how-to/import-export/overview#installing_config-connector">Bulk import and export resources documentation.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3d329446517" width="1" height="1" alt=""><hr><p><a href="https://medium.com/globant/infrastructure-as-code-using-kubernetes-d3d329446517">Infrastructure as Code using Kubernetes</a> was originally published in <a href="https://medium.com/globant">Globant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>