<?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 Nikhil Koduri on Medium]]></title>
        <description><![CDATA[Stories by Nikhil Koduri on Medium]]></description>
        <link>https://medium.com/@nikhil161096?source=rss-52645b94614c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6XyNA06z2CdkgcwkXQWzFQ@2x.jpeg</url>
            <title>Stories by Nikhil Koduri on Medium</title>
            <link>https://medium.com/@nikhil161096?source=rss-52645b94614c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 06:38:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikhil161096/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[Giving a spin to Cloud Datastream, The new serverless CDC offering on Google cloud]]></title>
            <link>https://blog.searce.com/giving-a-spin-to-cloud-datastream-the-new-serverless-cdc-offering-on-google-cloud-114f5132d3cf?source=rss-52645b94614c------2</link>
            <guid isPermaLink="false">https://medium.com/p/114f5132d3cf</guid>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[change-data-capture]]></category>
            <category><![CDATA[dataflow]]></category>
            <dc:creator><![CDATA[Nikhil Koduri]]></dc:creator>
            <pubDate>Sun, 30 May 2021 10:18:29 GMT</pubDate>
            <atom:updated>2021-05-30T10:18:29.000Z</atom:updated>
            <content:encoded><![CDATA[<p>Google recently introduced a serverless offering for change data capture (CDC). Prior to this, For all our CDC use-cases on the Google cloud platform, <a href="https://debezium.io/">Debezium</a> was used extensively to suffice the requirements. How can the same CDC use case be simplified using Datastream? Let’s find out.</p><h3><strong>Let us talk about what is Datastream about:</strong></h3><p><a href="https://cloud.google.com/datastream">Datastream</a> is a serverless offering that carries out <a href="https://en.wikipedia.org/wiki/Change_data_capture">CDC</a> and replication in a seamless manner. It supports Oracle, MySQL as the sources, and Cloud Storage as the destination as of now with PostgreSQL and Pubsub being added soon as source and destination respectively. Since Datastream is still in preview, we can expect it to support the synchronization of data across many more heterogeneous databases and applications until it reaches GA.</p><p><strong>Why would we choose Datastream over traditional CDC approaches:</strong></p><ul><li>Datastream provides a secured channel in terms of private connectivity options, which lets you associate Datastream VPC with the VPC of your desired choice.</li><li>Setting up CDC and replication with Datastream is effortless</li><li>Detailed monitoring provided by Datastreams that lets us analyze metrics like Throughput, Latency, Data freshness, and much more</li><li>No resource provisioning or management</li><li>Seamless autoscaling capabilities with minimal downtime</li><li>Ease of integration with various GCP data services such as Dataflow which opens up doors to multiple use cases and architecture for analytics, event-driven architecture, database replication, and much more</li></ul><p><strong>Now let&#39;s deep dive into Datastream and see what datastream comprises of:</strong></p><ul><li><strong>Private connectivity configurations:</strong> Private connectivity can be established using VPC peering connections making your data access secure</li><li><strong>Connection Profiles: </strong>Connection profiles are created to maintain information about your source and destination, These connection profiles will be used by the streams and ensure reusability across various streams</li><li><strong>Streams: </strong>Streams are the elements that consume the connection profiles and creates the CDC streams to desired source and destination</li></ul><h3><strong>Time to test Datastream out and see it in action:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*MbIv7Ywej5sHcnYAjnxM-g.jpeg" /></figure><p>We are going to set up a real-time CDC pipeline from MySQL to Bigquery as depicted in the above architecture. The Google cloud services we would be using for this is as follows:</p><ul><li><a href="https://cloud.google.com/sql"><strong>CloudSQL</strong></a><strong>: </strong>CloudSQL would be hosting the MySQL database from where we would be capturing all the changes and for that as it would be for any replication or CDC, enabling binlog is a prerequisite.</li><li><a href="https://cloud.google.com/datastream"><strong>Datastream</strong></a><strong>: </strong>Datastream would be capturing all the change events from the MySQL database and pushing them into Avro or JSON format onto GCS.</li><li><a href="https://cloud.google.com/dataflow"><strong>Dataflow</strong></a><strong>: </strong>Dataflow jobs will stream the data from Cloud storage and write them into Bigquery for further consumption using Apache Beam SDK.</li><li><a href="https://cloud.google.com/bigquery"><strong>Bigquery</strong></a><strong>: </strong>Bigquery, GCP’s managed data warehouse solution is where our data would be residing to further carry transformations or be queried directly</li></ul><p>For reasons of brevity, I would not be showcasing the creation of the cloudSQL for this demo, Just make sure that binary logging is enabled on your cloudSQL, this can either be done while creating the CloudSQL by enabling the Point-in-time recovery or can the CloudSQL instance can be patched later using the following command</p><pre>gcloud sql instances patch &lt;instance name&gt; --enable-bin-log</pre><p>I have created a sample table called Persons with the following schema that we would be carrying out our CDC on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*RgxvxE4kTxfXoEPoevDD9g.png" /></figure><p>Now let&#39;s go-ahead to the GCP console and start building the Datastream configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*Bb0_AcCXToYERupPdMAXeQ.png" /></figure><ul><li>Configure the Stream name and Stream ID, As for the region, the region of the stream should be the same region as the connection profile created.</li><li>Choose <strong>MySQL </strong>as the Source type and <strong>Cloud Storage</strong> as the Destination type</li><li>Along with the binary logging, We also have to provision a Datastream user, this can be done by the following commands:</li></ul><pre>mysql&gt; CREATE USER &#39;datastream&#39;@&#39;%&#39; IDENTIFIED BY &#39;[YOUR_PASSWORD]&#39;;</pre><pre>mysql&gt; GRANT REPLICATION SLAVE, SELECT, RELOAD, REPLICATION CLIENT, LOCK TABLES, EXECUTE ON *.* TO &#39;datastream&#39;@&#39;%&#39;;</pre><pre>mysql&gt; FLUSH PRIVILEGES;</pre><ul><li>As for CloudSQL we have to provide permissions to Datastream service account to read and create objects on the destination bucket. The email address of the service account will be <strong>service-[project_number]@gcp-sa-datastream.iam.gserviceaccount.com</strong></li><li>Select the destination bucket and assign the following permissions to it:</li></ul><pre>roles/storage.objectViewer <br>roles/storage.objectCreator<br>roles/storage.legacyBucketReader</pre><p>Next, we would be configuring the source and destination:</p><p>For both source and destination, we have to create connection profiles, first, we will configure the source, you will need to add the following details:</p><ul><li>Connection name and Connection ID</li><li>Hostname or IP of the cloudSQL or MySQL</li><li>Username and Password for the Datastream user created</li></ul><p>Next for the connectivity, you can use various connectivity method such as</p><ul><li>Private connectivity (VPC Peering)</li><li>IP Whitelisting</li><li>Proxy tunneling</li></ul><p>Choose the connectivity method of your choice and test the connectivity.</p><p>Once your connectivity is established you can test the connection to ensure the connection doesn&#39;t have any blockers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Upi5-bVibgtDc2d0pVwlfA.png" /></figure><p>Moving ahead, We get to choose which tables and schemas are to be included for the datastream to consider for the CDC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*PH1wJ-JZKMfADmZ6Q9fpXA.png" /></figure><p>Once done, We would be configuring the destination connection profile, wherein we just need to select the <strong>Bucket name</strong> where we would be storing our data on and any specific <strong>Path prefix</strong> to store our output files</p><p>The final step for the datastream creation is the file strategy for the output file to be stored</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*2iheaI10GjMMl3SJ-pUvJg.png" /><figcaption>You can choose between JSON and Avro format for the Output</figcaption></figure><p>The files will be written to Cloud storage once the Target file size or Writing data delay limitation has been reached.</p><p>In the final step, we can run validations, to validate the configuration and then click create and start to have the stream get started straight away.</p><p>And that&#39;s it, This is how simple it is to setup Datastream, Now the Datastream that we have created will ingest changes from the MySQL hosted on CloudSQL into the Datastream</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iFVZ2hvBJmjH8_iJMWGVjw.png" /></figure><p>So the next step is to replicate this change data into Bigquery, and that&#39;s where dataflow will help us achieve this.</p><p>Google has already populated Cloud Dataflow with templates to interact with Cloud Datastream. These templates can be used to load the data into Bigquery, PostgreSQL, and Cloud Spanner as depicted in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*Yy83-fkavYzMz_zUBSwqsA.png" /></figure><p>The template for Datastream to Bigquery requires three parameters apart from the optional ones to process further</p><ul><li>File location for the datastream output in GCS</li><li>Dataset name that will contain staging tables</li><li>Dataset name that will contain the replica tables</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*0eJH8tqgkwoiTz6hBHJhXw.png" /></figure><p>Now we are just going to run the dataflow the job and let the magic begin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*nCJrVIiDCspFNqdRXEFBYA.png" /></figure><p>As the Job starts running you would see tables created in the data in the bigquery datastream that you had mentioned in the template</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*v9Ig1cXi2V95xzlngKrSgQ.png" /></figure><p>The Persons table would contain the as-is data from the MySQL database.</p><p>The Persons_log table would contain the row per stream event which capture the change type that occurred like INSERT, UPDATE or DELETE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*0HWnZYOATWwhJ3Zyn_c7IA.png" /></figure><p>Now that your Operational data is being replicated to bigquery, you run your queries directly onto bigquery and also connect to various BI tools to visualize and analyze your data.</p><blockquote>Important thing to note, Datastream is still in preview and may have result into some bugs while running them.</blockquote><p>Hope this was helpful, Feel free to reach out to me on <a href="https://www.linkedin.com/in/nikhilkoduri/">Linkedin</a> in case of any queries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=114f5132d3cf" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/giving-a-spin-to-cloud-datastream-the-new-serverless-cdc-offering-on-google-cloud-114f5132d3cf">Giving a spin to Cloud Datastream, The new serverless CDC offering on Google cloud</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern CI/CD with Anthos]]></title>
            <link>https://blog.searce.com/modern-ci-cd-with-anthos-554c69c5dec2?source=rss-52645b94614c------2</link>
            <guid isPermaLink="false">https://medium.com/p/554c69c5dec2</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[gke]]></category>
            <category><![CDATA[anthos-config-management]]></category>
            <category><![CDATA[anthos]]></category>
            <category><![CDATA[cicd]]></category>
            <dc:creator><![CDATA[Nikhil Koduri]]></dc:creator>
            <pubDate>Wed, 18 Nov 2020 07:27:10 GMT</pubDate>
            <atom:updated>2020-11-18T07:58:20.894Z</atom:updated>
            <content:encoded><![CDATA[<p>With the increase in the adoption for hybrid and multicloud deployments, It has become imperative that we have to rise up from the traditional CI/CD strategies and start incorporating modern practices that facilitates us for rolling out of security policies and config management along with application deployment.</p><p>Modern CI/CD brings in the Developers, Operators and Security Admins into a single unit instead of silos. Thus the deployment of any change is highly coupled with the supported aspects such as the policy or network changes.</p><p>Modern CI/CD changes the focus of Developers from worrying about the deployment practices and helps security to share interface and operating models with developments and operations. This also makes it easier for incorporation of security features from google such as binary authorisation while ensuring git based workflows for all the changes. Modern CI/CD allows us to templatize and centrally manage policies across hybrid and multi-cloud deployments.</p><h3>Workflow and Team responsibilities</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZZwOv3FcNLCb2OY6.jpg" /><figcaption>Roles in Modern CI/CD</figcaption></figure><p>Git becomes the common source of truth for all the codes, policies and deployment manifests across all the teams.</p><p>The <strong>App Developers </strong>build their code and store the changes in the code in the application repository. These changes and application code triggers the Continuous integration tools such as Jenkins or gitlab runners that can build the code and create artifacts out of it.</p><p>Once the artifacts are generated,these are referenced in the deployment repository which are managed by the <strong>Operators</strong>. These yamls or json files are collected from the source of truth i.e the common repository. The manifests from the common repository is then converted into the hydrated manifests for staging and production branches with the help of tools such as kustomize. The staging branches are an exact replica of the production deployments. Once the code is merged with the staging branch, Continuous delivery tools such as spinnaker and skaffold deploy these applications to the respective clusters.</p><p><strong>Security administrators</strong> utilize their own git repository to store the policies that are applied to your clusters such as RBAC or network policy. Policy controller from <a href="https://cloud.google.com/anthos/config-management"><strong>anthos config management</strong></a> helps them to enforce security policy across all clusters without the head scratching activities such as configuring across all clusters.</p><blockquote>Anthos Config management is part of the Anthos package that helps users enforce policies like RBAC, namespaces and more across kubernetes clusters on on-prem and across cloud. Anthos config management uses declarative approach to maintain state of the cluster and enforced policies using git as source of truth.</blockquote><h3>What will we do here?</h3><p>We are going to provision two clusters across clouds i.e Google cloud and AWS with the help of <a href="https://cloud.google.com/anthos/gke/docs/aws"><strong>Gke-on-Aws</strong></a>, Look into how to achieve modern CI/CD across these clusters, And how security admins can rollout kubernetes policies efficiently using Anthos config management.</p><p>Let us begin with Setting up the clusters.</p><p><strong>Prerequisites</strong></p><ul><li>Terraform — Terrafom is used by the anthos-gke tool to provision resources in aws.</li><li>Kubectl — Kubectl tool will be used to interact with the kubernetes clusters and also provision the AWS nodepools for Anthos cluster on AWS</li><li>Nomos — Nomos commandline tool will be used for interacting with anthos config management and check the status of syncs of current config rollouts and also troublehshoot any errors that we see.</li><li>AWS cli — AWS cli needs to be installed and configured with <strong>access key</strong> and <strong>secret key </strong>of the user that we would be using to deploy the infrastructure on AWS.</li><li><strong>Anthos-gke</strong> — This is the command line tools that will be used to create terraform templates and deploy anthos infrastructure. The steps to download the tool are as follows:</li></ul><pre>gsutil cp gs://gke-multi-cloud-release/aws/aws-1.5.0-gke.6/bin/linux/amd64/anthos-gke .</pre><pre>chmod 755 anthos-gke<br>sudo mv anthos-gke /usr/local/bin</pre><h3><strong>Getting the Infrastructure ready</strong></h3><h4><strong>Creating the GKE-on-AWS clusters</strong></h4><p>We would need to enable the respective API’s in google cloud to work with the deployment and application of the cluster.</p><pre>export PROJECT_ID=&lt;project-name&gt;<br>gcloud config set core/project ${PROJECT_ID}<br>export PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_ID} --format &#39;value(projectNumber)&#39;)<br>gcloud services enable anthos.googleapis.com<br>gcloud services enable cloudresourcemanager.googleapis.com<br>gcloud services enable gkehub.googleapis.com<br>gcloud services enable gkeconnect.googleapis.com<br>gcloud services enable logging.googleapis.com<br>gcloud services enable monitoring.googleapis.com<br>gcloud services enable serviceusage.googleapis.com<br>gcloud services enable stackdriver.googleapis.com<br>gcloud services enable storage-api.googleapis.com<br>gcloud services enable storage-component.googleapis.com</pre><p>We have to create 3 service account that we would be using for deploying the required infrastructure and connecting to hub.</p><pre>gcloud iam service-accounts create management-sa<br>gcloud iam service-accounts create hub-sa<br>gcloud iam service-accounts create node-sa</pre><p>JSON keys from these service accounts would be required while creating the manifest files for anthos-gke tool.</p><pre>gcloud iam service-accounts keys create management-key.json \<br>     --iam-account management-sa@$PROJECT_ID.iam.gserviceaccount.com<br>gcloud iam service-accounts keys create hub-key.json \<br>     --iam-account hub-sa@$PROJECT_ID.iam.gserviceaccount.com<br>gcloud iam service-accounts keys create node-key.json \<br>     --iam-account node-sa@$PROJECT_ID.iam.gserviceaccount.com</pre><p>Grant roles to the management service account.</p><pre>gcloud projects add-iam-policy-binding \<br>    $PROJECT_ID \<br>    --member serviceAccount:management-sa@$PROJECT_ID.iam.gserviceaccount.com \<br>    --role roles/gkehub.admin<br>gcloud projects add-iam-policy-binding \<br>    $PROJECT_ID \<br>    --member serviceAccount:management-sa@$PROJECT_ID.iam.gserviceaccount.com \<br>    --role roles/serviceusage.serviceUsageViewer</pre><p>Grant roles to the hub service account.</p><pre>gcloud projects add-iam-policy-binding \<br>    $PROJECT_ID \<br>    --member serviceAccount:hub-sa@$PROJECT_ID.iam.gserviceaccount.com \<br>    --role roles/gkehub.connect</pre><p>Grant roles to the node service account.</p><pre>gcloud projects add-iam-policy-binding \<br>      $PROJECT_ID \<br>      --member serviceAccount:node-sa@$PROJECT_ID.iam.gserviceaccount.com \<br>      --role roles/storage.objectViewer</pre><p>We need to add IAM access to these service account.</p><pre>gcloud projects add-iam-policy-binding \<br>    $PROJECT_ID \<br>    --member serviceAccount:management-sa@$PROJECT_ID.iam.gserviceaccount.com \<br>    --role roles/gkehub.admin<br>gcloud projects add-iam-policy-binding \<br>    $PROJECT_ID \<br>    --member serviceAccount:management-sa@$PROJECT_ID.iam.gserviceaccount.com \<br>    --role roles/serviceusage.serviceUsageViewer</pre><p>Once we have set all the env and added all the required access for the service account, we can proceed to reserving KMS keys on AWS that we would use for management service.</p><ol><li>Navigate to <strong>KMS</strong> and select <strong>Customer managed keys</strong> from the side bar.</li><li>Click <strong>Create Key</strong>.</li><li>Leave the default options selected.</li><li>Once created, select the key from the list.</li><li>Copy the key’s ARN.</li><li>Repeat the preceding steps for another key.</li></ol><p>Now that we have all the prerequisites nailed down, We can go ahead and create management service.</p><p><strong>Management Service</strong></p><p>Create anthos-gke.yaml that will contain the details for the deployment of the master plane.</p><pre>apiVersion: multicloud.cluster.gke.io/v1<br>kind: AWSManagementService<br>metadata:<br>  name: management<br>spec:<br>  version: aws-1.5.0-gke.6<br>  region: us-east-1<br>  authentication:<br>    awsIAM:<br>      adminIdentityARNs:<br>      - &lt;ADMIN ARN&gt;<br>  kmsKeyARN: &lt;KMS_KEY 1&gt;<br>  databaseEncryption:<br>    kmsKeyARN: &lt;KMS_KEY 2&gt;<br>  googleCloud:<br>    projectID: &lt;GCP Project ID&gt;<br>    serviceAccountKeys:<br>      managementService: /home/nikhil_koduri/anthos/management-key.json<br>      connectAgent: /home/nikhil_koduri/anthos/hub-key.json<br>      node: /home/nikhil_koduri/anthos/node-key.json<br>  dedicatedVPC:<br>    vpcCIDRBlock: 10.1.0.0/16<br>    availabilityZones:<br>    - us-east-1a<br>    privateSubnetCIDRBlocks:<br>    - 10.1.1.0/24<br>    publicSubnetCIDRBlocks:<br>    - 10.1.2.0/24<br>  # Optional<br>  bastionHost:<br>    allowedSSHCIDRBlocks:<br>    - 0.0.0.0/0</pre><p>The values in the above YAML needs to be replaced according with the following details:</p><pre>&lt;ADMIN ARN&gt; : ARN for the AWS user that will be used for resource deployment<br>&lt;KMS_KEY 1/2&gt; : KMS key reserved in the earlier steps<br>&lt;GCP Project ID&gt; : Project ID for the gcp project to be used</pre><p>You can also change the network configuration mentioned in the above YAML.</p><p>Once we are happy with the configuration details in the file, we can go ahead and start provisioning resources</p><pre>anthos-gke aws management init</pre><p>This commands creates various terraform files that are essential to deploy infrasture on aws for anthos to run. The values passed from the yaml above gives us the terraform needed to deploy the same.</p><pre>anthos-gke aws management apply</pre><p>This command takes approx 10 mins for the control plane and nodes to be deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*reWfZZu2A8dRWNwlwJUwRA.png" /></figure><p>The above command creates a bastion host that can be used to carryout kubectl commands. To connect to bastion host run the following script.</p><pre>terraform output bastion_tunnel &gt; bastion-tunnel.sh<br>chmod 755 bastion-tunnel.sh<br>./bastion-tunnel.sh -N</pre><p>Once the tunnel is connected, you can open a new terminal and start running kubectl commands.</p><p>We can use the anthos-gke cli to create kubeconfig for us to connect to the cluster.To generate the kubeconfig for master cluster, we have to run the following command.</p><pre>anthos-gke aws management get-credentials</pre><p>We can confirm this by running the kubectl commands.</p><pre>env HTTP_PROXY=http://localhost:8118 \<br>kubectl cluster-info</pre><p><strong>Creating user cluster</strong></p><p>Now that we have got our control plane setup, we can go ahead and start deploying the user cluster.</p><p>Make sure you are in the directory of the managment service files and then we would be using the terraform output to deploy the cluster and nodepools.</p><pre>terraform output cluster_example &gt; cluster-0.yaml</pre><p>we can configure the cluster-0 yaml to change the node size and node configurations.</p><p>Once satisfied with the cluster configuration, go ahead and apply it.</p><pre>env HTTP_PROXY=http://localhost:8118 \<br>  kubectl apply -f cluster-0.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*48aC8D8gd2KlGVqVvQk23Q.png" /></figure><p>This would create the AWS cluster and AWS nodepools resources in kuberntes</p><p>We can run the kubectl get events command to check the status of the deployment.</p><p>We can also check the status of provisioned cluster with kubectl get command</p><pre>env HTTP_PROXY=http://localhost:8118 \<br>  kubectl get AWSClusters</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*0d_jaZVH8qK_RZZD1jI8ww.png" /></figure><p>To get access into the Anthos user cluster, we just need to pass the cluster name along with the anthos-gke get credentials command.</p><pre>env HTTP_PROXY=http://localhost:8118 \<br>  anthos-gke aws clusters get-credentials cluster-0</pre><p><strong>Connecting AWS cluster to Cloud console</strong></p><p>Now that the cluster is created and We can go ahead use GKE connect to register the cluster to the console.</p><blockquote>Note: The following commands have to be run in the user cluster.</blockquote><p>The first step is to create a kubernetes service account and provide it with the cluster admin role</p><pre>env HTTP_PROXY=http://localhost:8118 \<br>kubectl create serviceaccount -n kube-system admin-user</pre><pre>env HTTP_PROXY=http://localhost:8118 \<br>kubectl create clusterrolebinding admin-user-binding \<br>  --clusterrole cluster-admin --serviceaccount kube-system:admin-user</pre><p>After successful creation of the same, we would be taking the token from the service account to register it on the cloud console.</p><pre>SECRET_NAME=$(env HTTP_PROXY=http://localhost:8118 \<br>kubectl get serviceaccount -n kube-system admin-user \<br>  -o jsonpath=&#39;{$.secrets[0].name}&#39;)</pre><pre>env HTTP_PROXY=http://localhost:8118 \<br>kubectl get secret -n kube-system ${SECRET_NAME} -o jsonpath=&#39;{$.data.token}&#39; \<br>  | base64 -d | sed $&#39;s/$/\\\n/g&#39;</pre><p>This gives us the token saved as the secret on the GKE cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7XXBYvgY6_FqT9Pc1X0KQ.png" /></figure><p>Go the connect page on gke and under anthos managed cluster and select login, you can paste the copied token in the token field and choose login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*OHgzo8Lhw8vInJzb32xpCw.png" /></figure><p>Voila! Your GKE-on-AWS cluster is created and registered in GCP console.</p><h4><strong>Creating GKE Cluster</strong></h4><p>To showcase the flexibility of hybrid cloud that we can achieve for anthos, we would be creating the second cluster in google cloud.</p><p>Export the cluster names to register them to the gke hub</p><pre>export CLUSTER1_NAME=anthos-cluster-us-central-1<br>export CLUSTER1_LOCATION=us-central1-c</pre><p>Lets create the cluster and get workload identity enabled on the cluster.</p><pre>gcloud beta container --project ${project_id} clusters create ${CLUSTER1_NAME} --zone ${CLUSTER1_LOCATION} --no-enable-basic-auth --cluster-version &quot;1.17.12-gke.1504&quot; --release-channel &quot;regular&quot; --machine-type &quot;e2-standard-2&quot; --image-type &quot;COS&quot; --disk-type &quot;pd-standard&quot; --disk-size &quot;100&quot; --metadata disable-legacy-endpoints=true --scopes &quot;<a href="https://www.googleapis.com/auth/cloud-platform">https://www.googleapis.com/auth/cloud-platform</a>&quot; --num-nodes &quot;2&quot; --enable-stackdriver-kubernetes --enable-ip-alias --network &quot;projects/${project_id}/global/networks/default&quot; --subnetwork &quot;projects/${project_id}/regions/us-central1/subnetworks/default&quot; --default-max-pods-per-node &quot;110&quot; --enable-autoscaling --min-nodes &quot;0&quot; --max-nodes &quot;5&quot; --no-enable-master-authorized-networks --addons HorizontalPodAutoscaling,HttpLoadBalancing,ConfigConnector --enable-autoupgrade --enable-autorepair --max-surge-upgrade 1 --max-unavailable-upgrade 0 --workload-pool &quot;${project_id}.svc.id.goog&quot;</pre><p>Create memberships for the cluster to add them to the gke cluster</p><pre>gcloud beta container hub memberships register ${CLUSTER1_NAME} \<br>   --gke-cluster=${CLUSTER1_LOCATION}/${CLUSTER1_NAME} \<br>   --enable-workload-identity</pre><p>Make sure the hub service account has appropriate IAM permissions gke hub connect</p><pre>gcloud projects add-iam-policy-binding \<br>&lt;project-id&gt; \<br>--member &quot;serviceAccount:&lt;project-id&gt;.hub.id.goog[gke-connect/connect-agent-sa]&quot; \<br>--role &quot;roles/gkehub.connect&quot;</pre><p>Let us start with the CI/CD setup</p><h3><strong>CI/CD setup</strong></h3><p>For setting up the modern CI/CD we would be creating four git repositories.</p><ul><li><strong>modern-cicd-anthos-app</strong> — This would contain the application code and will be used to push by the developers</li><li><strong>shared-cicd </strong>— This would contain the standardised yaml for deployment of the kubernetes resources which would be maintained by the operators</li><li><strong>modern-cicd-anthos-env </strong>— This repository would be end product that would contain the hydrated manifests that would be populated automatically and used for the continuous deployments.</li><li><strong>csp-config-management </strong>— This repository to would contain the acm policies and policy and would be used by the security operators to rollout policies.</li></ul><p>Let us begin in looking into how the CI/CD setup would be defined and how it would function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*ACRJtx6wpyJBOpem5AOwlg.jpeg" /></figure><p>So we will start with the shared CI/CD repository.</p><p>We will start by creating a the standard template for the deployment that will be hydrated with the application specific manifests.</p><pre>kind: Deployment<br>apiVersion: apps/v1<br>metadata:<br>  name: app<br>spec:<br>  strategy:<br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxUnavailable: 0<br>  template:<br>    metadata:<br>      name: app<br>    spec:<br>      containers:<br>      - name: app<br>        image: &lt;GCR_URL&gt;<br>        resources:<br>          limits:<br>            memory: &quot;512Mi&quot;<br>            cpu: &quot;500m&quot;<br>        env:<br>        - name: ENVIRONMENT<br>          value: base<br>        - name: LOG_LEVEL<br>          value: info<br>        readinessProbe:<br>          initialDelaySeconds: 1<br>          periodSeconds: 1<br>          httpGet:<br>            path: /healthz<br>            port: 8080<br>        ports:<br>        - name: http<br>          containerPort: 8080</pre><p>Also we would be creating the template for the service deployment as well.</p><pre>kind: Service<br>apiVersion: v1<br>metadata:<br>  name: app<br>spec:<br>  type: ClusterIP<br>  ports:<br>  - name: http<br>    port: 8080<br>    targetPort: 8080<br>    protocol: TCP</pre><p>This becomes a source of truth that will be merged with the application code using kustomize. Hence let us go ahead and configure the kustomization.yaml for these two files.</p><pre>resources:<br>  - service.yaml<br>  - deployment.yaml</pre><p>Now that we have got the shared CI/CD nailed down, Let us go ahead and work on our application code.</p><p>Below is the application code that we would be deploying for this demo.</p><pre>package main<br><br>import (<br>	&quot;fmt&quot;<br>	&quot;log&quot;<br>	&quot;net/http&quot;<br>	&quot;os&quot;<br>)<br><br>func main() {<br>	env := os.Getenv(&quot;ENVIRONMENT&quot;)<br>	port := 8080<br>	log.Printf(&quot;Running in environment: %s\n&quot;, env)<br><br>	http.HandleFunc(&quot;/&quot;, func(w http.ResponseWriter, r *http.Request) {<br>		log.Printf(&quot;Received request from %s at %s&quot;, r.RemoteAddr, r.URL.EscapedPath())<br>		fmt.Fprint(w, &quot;Hello World !&quot;)<br>	})<br>	http.HandleFunc(&quot;/healthz&quot;, func(w http.ResponseWriter, r *http.Request) {<br>		log.Printf(&quot;Received health check from %s&quot;, r.RemoteAddr)<br>		w.WriteHeader(http.StatusOK)<br>	})<br>	log.Printf(&quot;Starting server on port: %v&quot;, port)<br>	log.Fatal(http.ListenAndServe(fmt.Sprintf(&quot;:%v&quot;, port), nil))<br><br>}</pre><p>This is just a sample http application that would print the “hello world” as text. Now we would go ahead and write a Dockerfile to containerize this.</p><pre>FROM golang:1<br>WORKDIR /app<br>COPY *.go ./<br>RUN go build -o golang-template<br>CMD [&quot;/app/golang-template&quot;]</pre><p>For this demo we would be using skaffold to be deploying the code and use kustomize to get staging and production manifests.</p><p>So lets run the following commands to set that up.</p><pre>mkdir -p ./k8s/dev/<br>mkdir -p ./k8s/stg/<br>mkdir -p ./k8s/prod</pre><p>Thus we have three different folders created for different environments that are present in your organization.</p><p>We would be creating the deployment.yaml in all these three folders.</p><pre>kind: Deployment<br>apiVersion: apps/v1<br>metadata:<br>  name: app<br>spec:<br>  template:<br>    spec:<br>      containers:<br>      - name: app<br>        env:<br>        # Required for Skaffold to detect runtime language<br>        # https://skaffold.dev/docs/workflows/debug/#go<br>        - name: GOTRACEBACK<br>          value: single<br>        - name: ENVIRONMENT<br>          value: dev</pre><p>So the kustomize would be referring to the shared-cicd repository for the bases and this would merge the code from the same to create our deployment manifests.</p><p>The following kustomization yaml would take up the script and create the hydrated deployment for us.</p><pre>bases:<br>- git@github.com:nikhilkoduri-searce/shared-cicd.git<br>patches:<br>- deployment.yaml<br>namePrefix: &quot;golang-template-&quot;<br>commonLabels:<br>  app: golang-template<br>  role: backend</pre><p>Next, we need to configure our skaffold yaml to run this and also fix manual errors in developement mode.</p><pre>apiVersion: skaffold/v2beta5<br>kind: Config<br># Defaults are configured for local dev<br>build:<br>  artifacts:<br>  - image: gcr.io/searce-anthos-lab/anthos-app<br>deploy:<br>  kustomize:<br>    paths:<br>    - k8s/dev<br>profiles:<br>  # Profile used when building images in CI<br>  - name: ci<br>    build:<br>      cluster:<br>        dockerConfig:<br>          path: ~/.docker/config.json<br>  # Profile used when rendering production manifests<br>  - name: prod<br>    deploy:<br>      kustomize:<br>        paths:<br>        - k8s/prod<br>  # Profile used when rendering staging manifests<br>  - name: staging<br>    deploy:<br>      kustomize:<br>        paths:<br>        - k8s/stg</pre><p>Now to start the deployment practice lets create a new branch which we would later merge with main branch to trigger the ci pipeline.</p><pre>git checkout -b new-feature-branch</pre><p>we can test the code live on the dev clusters.</p><pre>skaffold-dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aiSdNQpNyGQYJKs840pxQg.png" /></figure><p>The code is deployed and we can live monitor the logs as well.</p><p>We can merge in to the master branch and get the CI pipeline triggered.We will be using Jenkins here to get the application CI and CD pipelines triggered. You can use any CI tool to build the image and push it to your docker repository.</p><p>Next we would be working on the `<em>modern-cicd-anthos-env</em>` repository. Once the docker image has been pushed to the repository, we want to generate the hydrated yamls. We would be using the jenkins repository along with the kustomize to hydrate these. So lets have a look at the Jenkinsfile.</p><pre>pipeline {<br>  agent any<br>  stages {</pre><pre>stage(&#39;Checkout&#39;) {<br>      steps {<br>        checkout scm<br>      }<br>    }</pre><pre>stage(&#39;set PATH env&#39;) {<br>      steps {<br>        sh &#39;export KUSTOMIZATION_PATH_STG=./k8s/stg&#39;<br>        sh &#39;export KUSTOMIZATION_PATH_PROD=./k8s/prod&#39;<br>      }<br>    }</pre><pre>stage(&#39;hydrate-manifests-stg&#39;) {<br>      steps {<br>          sh &#39;mkdir -p hydrated-manifests/&#39;<br>          sh &#39;kustomize build ${KUSTOMIZATION_PATH_STG} -o hydrated-manifests/stg.yaml&#39;<br>        }<br>    }</pre><pre>stage(&#39;hydrate-manifests-prod&#39;) {<br>      steps {<br>          sh &#39;kustomize build ${KUSTOMIZATION_PATH_PROD} -o hydrated-manifests/prod.yaml&#39;<br>        }<br>    }</pre><pre>stage(&#39;push hydrated manifests&#39;) {<br>      steps {<br>          sh &#39;git clone <a href="/service/mailto:git@github.com">git@github.com</a>:nikhilkoduri-searce/modern-cicd-anthos-env.git&#39;<br>          sh &#39;cd modern-cicd-anthos-env&#39;<br>          sh &#39;cp ../hydrated-manifests/stg.yaml stg.yaml&#39;<br>          sh &#39;cp ../hydrated-manifests/prod.yaml prod.yaml&#39;<br>          sh &#39;git add stg.yaml prod.yaml&#39;<br>          sh &#39;git commit -m &quot;updates&quot;&#39;<br>          sh &#39;git push origin staging&#39;<br>        }<br>    }</pre><pre>}<br>}</pre><p>Let us breakdown the steps that this jenkins file would do.</p><ul><li>Stage: hydrate-manifests — kustomize will build the kustomization yaml from the shared repository and hydrate it with the application deployment manifests to create the stg.yaml that would be used for deployment in the staging enviornments, Same would be ocurring for the production stage as well.</li><li>Stage:push hydrated manifests — Once the hydrated manifests are created jenkins will pull the git repository and copy the new hydrated manifests to the `<em>modern-cicd-anthos-env</em>` and push it to staging branch.</li></ul><p>Once the code is pushed to the staging the cd pipeline would deploy it to the staging cluster .</p><p>For carrying out the CD for the hydrated yaml files we would be using the <a href="https://cloud.google.com/blog/products/devops-sre/introducing-the-jenkins-gke-plugin-deploy-software-to-your-kubernetes-clusters">Jenkins GKE Plugin</a> to deploy to the staging and production clusters.</p><p>To achieve this, we need to install the following plugins.</p><ul><li>Jenkins GKE Plugin</li><li>Google Oauth Plugin</li></ul><p>To get jenkins authenticated to deploy the pods to the kubernetes cluster. We would be using the be using the google sa to authenticate. Once the service account is generated we would be creating a credential to add jenkins credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*WQsFX8TR6r6_AZmu4DqbbQ.png" /><figcaption>Manage Jenkins &gt; Manage Credentials &gt; Add Credentials</figcaption></figure><p>Add the project name and the service account key to the the credentials and we would be using these credentials to authenticate.</p><p>Next we would be creating the Jenkins pipeline using the following Jenkins file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c01bedf462e3e27fe195fb2b1529b38/href">https://medium.com/media/7c01bedf462e3e27fe195fb2b1529b38/href</a></iframe><p>Replace fields such as project-id , zone , clustername in the above jenkinsfile and push the yaml in the <em>modern-cicd-anthos-env repository.</em></p><p>Once the code is pushed and merged to staging branch, the deployment would be triggered and stg.yaml would start to get deployed.</p><blockquote>Note: Automated triggers for jenkins needs to be build manually for the first time</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*zBIUdDzW7GAcxOjSHEM8Pg.png" /></figure><p>On successful build, the application will be deployed to the staging clusters as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*Jfap8UxnmrSHe4D6YLBdrQ.png" /></figure><p>Now that we are satisfied with the deployment we can move ahead to deploying to production.</p><p>To deploy it to the the production clusters, we just have to merge the branch to the main or master branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*rDu9mBXJeoLzfE6KdTsH3A.png" /></figure><p>On successful merge similar cd pipeline for the production cluster would be triggered from main or master branch and would start deploying them to production cluster in few seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*BXrcDZqf-gLSbrCRgoEXxg.png" /></figure><h3>Installing Anthos Config Management on all clusters</h3><p>We have observed how developers and operators would deploy applications, now its time to dice into how security admins would enfore policies and constraints in an automated way.</p><blockquote>Note: This step needs to be carried out on all GKE as well as GKE-on-AWS clusters.</blockquote><p>We would need to download config management operator into all the GKE cluster created.</p><pre>gsutil cp gs://config-management-release/released/latest/config-management-operator.yaml config-management-operator.yaml<br>kubectl apply -f config-management-operator.yaml</pre><p>Once deployed, you should see the pods created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZmqjtN98zX_Fl4XuPVwkMw.png" /></figure><p>Now that the operator is installed, lets move to creating creds for acm to validate with the git repo</p><p>We would be consuming ssh keys for authentication. So lets go ahead and create one.</p><pre>ssh-keygen -t rsa -b 4096 \<br> -C &quot;acm-demo&quot; \<br> -N &#39;&#39; \<br> -f /root/anthos/acm-demo</pre><p>This key needs to be saved as `git-creds` named secret</p><pre>kubectl create secret generic git-creds \<br> --namespace=config-management-system \<br> --from-file=ssh=/root/anthos/acm-demo</pre><p>Add the key in your git ssh key.</p><figure><img alt="sdadasdas" src="https://cdn-images-1.medium.com/max/778/1*_y7Z6ljmqPXNxnuQV7yA5Q.png" /></figure><p>Now that we have the keys created we will go ahead and create the configmanagement resources</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed1d36aa3d46a1aff296efa08166049c/href">https://medium.com/media/ed1d36aa3d46a1aff296efa08166049c/href</a></iframe><p>Once the resources are created you can run the following command to check the status</p><pre>nomos status</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*SJR1YhKYcv1HfnjXySAtOg.png" /></figure><p>Now we can go ahead and initialise our repository.</p><p>We can run nomos initcommand to get standard deployment template ready.</p><p>Once the sturcture is created you can add configs in the namespaces folder to create the namespace.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4ec9dffc0cd81481eead04e8cb7d7c1/href">https://medium.com/media/b4ec9dffc0cd81481eead04e8cb7d7c1/href</a></iframe><p>And just pushing the code to git repository would enable us to manage audit namespace.</p><p><strong>Policy Controller</strong></p><p>Security Admins play to role of rolling out security policies and constraints in mordern CI/CD. Let us see how we can rollout a constraint.</p><p>Make sure the policy controller is installed on the gke cluster, you can check this in the Anthos console on google cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*-E7sDj_Mys57Pbubc7Flfw.png" /><figcaption>you can enable the policy controller by editing the clusters</figcaption></figure><p>We would be creating a constraint that would restrict creation of namespaces that doesn’t contain the label `go`</p><pre># ns-must-have-go.yaml</pre><pre>apiVersion: constraints.gatekeeper.sh/v1beta1<br>kind: K8sRequiredLabels<br>metadata:<br>  name: ns-must-have-geo<br>spec:<br>  match:<br>    kinds:<br>      - apiGroups: [&quot;&quot;]<br>        kinds: [&quot;Namespace&quot;]<br>  parameters:<br>    labels:<br>      - key: &quot;go&quot;</pre><p>We would be using ACM to rollout this constraint. The policy constraints are to be placed in the clusters directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*Nh6leyzA7M3BB0A7ozALiA.png" /></figure><p>Once the new configuration is pushed, you can see it being created in the clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*LXUj6PtlbX50LN4gmUtp5A.png" /></figure><p>Lets go ahead and delete the audit namespace now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*g7NfxL_iJEZZ6pMJn-MRuQ.png" /></figure><p>As we can see the namespace is not being created as it doesn’t suffice the policy constraint, lets add label to the namespace.</p><pre>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: audit<br>  labels:<br>    go: production</pre><p>Now we can push this to the config repository and see the changes take place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*dpdUS-tDmQj9nFatcHqr5g.png" /></figure><p>And this is how Security Admins will roll out the security policies that validate the deployments before the CD steps.</p><p>Thus, We have created Anthos clusters and configured mordern ci/cd along with security policy with help of ACM. Feel free to reach out with queries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=554c69c5dec2" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/modern-ci-cd-with-anthos-554c69c5dec2">Modern CI/CD with Anthos</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Multiple Google Managed Certificate with single Kubernetes Ingress]]></title>
            <link>https://blog.searce.com/using-multiple-google-managed-certificate-with-single-kubernetes-ingress-29c78ca4a013?source=rss-52645b94614c------2</link>
            <guid isPermaLink="false">https://medium.com/p/29c78ca4a013</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Nikhil Koduri]]></dc:creator>
            <pubDate>Thu, 23 May 2019 17:18:19 GMT</pubDate>
            <atom:updated>2019-06-12T10:00:44.393Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are not aware of it, Google cloud platform recently have released managed SSL certificate. It is a quite cool feature wherein the SSL certificates are obtained <a href="https://cloud.google.com/load-balancing/docs/ssl-certificates#managed-certs">as well as managed by Google cloud platform and these SSL certificates</a> can be incorporated with kubernetes ingress and GKE. Well, it would be even cooler to integrate the kubernetes ingress with multiple certificates.</p><p><strong>So let&#39;s get started with it.</strong></p><p>Just for the sake of keeping this brief, we are going to use google cloud commands to create our GCP resources.</p><pre>gcloud beta container --project &quot;searce-playground&quot; clusters create &quot;multiple-ssl-cluster&quot; --zone &quot;us-central1-a&quot;  --cluster-version &quot;1.12.7-gke.10&quot; --machine-type &quot;custom-2-4096&quot; --image-type &quot;COS&quot; --disk-type &quot;pd-standard&quot; --disk-size &quot;100&quot;</pre><p><strong>Note:</strong> Managed certificates require clusters with masters running Kubernetes <strong>1.12.6-gke.7</strong> or higher and for Regional Clusters, you will need <strong>1.12.7-gke.17</strong></p><p><strong>Prerequisites</strong></p><ul><li>You must own a domain name.</li><li>reserved (static) external IP address on google cloud.</li></ul><pre>gcloud compute addresses create web-static-ip --global</pre><p>you can check the static IP created using the following command</p><pre>gcloud compute addresses describe web-static-ip --global</pre><p>This IP address needs to be configured in your domain’s DNS records.</p><p><strong>Once you are all set with the prerequisites, we can start with deploying the resources:</strong></p><p>I am going to use a sample deployment with two containers running into for this demo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47b36db4c3a07c183366d17ce5d39b41/href">https://medium.com/media/47b36db4c3a07c183366d17ce5d39b41/href</a></iframe><p>Expose this deployment using a NodePort:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8067935c29b49bc6e50de6789168193/href">https://medium.com/media/b8067935c29b49bc6e50de6789168193/href</a></iframe><p>Time to create these resources:</p><pre><strong>kubectl apply -f sample-deployment.yaml</strong><br>deployment.apps/my-mc-deployment created</pre><pre><strong>kubectl apply -f sample-service.yaml<br></strong>service/my-mc-service created</pre><h3>Managed Certificates</h3><p>For this demo, I am going to use two domains i.e <strong>abc.searce.tk</strong> and <strong>xyz.searce.tk </strong>and therefore would be creating two certificates for both the domain.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b971ded36f7b02819e99e64bc1a874b9/href">https://medium.com/media/b971ded36f7b02819e99e64bc1a874b9/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56d3f4135902ef099beaa30d595fed31/href">https://medium.com/media/56d3f4135902ef099beaa30d595fed31/href</a></iframe><p>Let us apply these as well:</p><pre><strong>kubectl create -f abc-cert.yaml<br></strong>managedcertificate.networking.gke.io/example-certificate-abc created</pre><pre><strong>kubectl create -f xyz-cert.yaml<br></strong>managedcertificate.networking.gke.io/example-certificate-xyz created</pre><p>You can check the certificate resources using the following command:</p><pre>kubectl get managedcertificate.networking.gke.io</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*dXZxIG_BgJTYH9gXLlqIGg.png" /></figure><h3>Kubernetes Ingress</h3><p>Now that we are ready with our Managed Certificates, Let us create the ingress resource.</p><ul><li>We are going to use the annotations to set the name of the certificates, as we are using multiple certificates we are going to specify them using <strong>comma-separated values</strong>.</li></ul><blockquote>Google cloud documentation does not specify how to serve multiple google managed SSL certificates from the same ingress or how to specify them in the ingress yaml.</blockquote><ul><li>The static IP reserved initially would also be used by the Ingress through the annotations as well.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a342dd7428a4b0cd236efdf4ed170f4/href">https://medium.com/media/2a342dd7428a4b0cd236efdf4ed170f4/href</a></iframe><p>Create the ingress:</p><pre>kubectl apply -f ingress.yaml</pre><p>Check the ingress created:</p><pre>kubectl get ingress</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*oH5Hff4lv41u00eZlJxlHQ.png" /><figcaption>ingress consists of both the host abc.searce.tk and xyz.searce.tk</figcaption></figure><p>Ingress would consume a good amount of time to have the GCP load balancing functioning as you can see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*3XWbI2x7wENucFAx9Si7JA.png" /><figcaption>From google cloud documentation</figcaption></figure><p>Once everything is in place, you can browse the hostnames and the contents will be served with the SSL certificates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*q__AboTSbG6r_kz2PJLfrQ.png" /><figcaption>abc.searce.tk</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*KAwar5cJIh5GjrJ4KusLuQ.png" /><figcaption>xyz.searce.tk</figcaption></figure><p>And that&#39;s it!!! we have multiple google managed SSL certificates serving from a single kubernetes Ingress.</p><p>Hope this was useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29c78ca4a013" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/using-multiple-google-managed-certificate-with-single-kubernetes-ingress-29c78ca4a013">Using Multiple Google Managed Certificate with single Kubernetes Ingress</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes deployment on Google Compute Engine using Terraform]]></title>
            <link>https://blog.searce.com/kubernetes-deployment-on-google-compute-engine-using-terraform-8d6075cf4d3f?source=rss-52645b94614c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d6075cf4d3f</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[google-cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Nikhil Koduri]]></dc:creator>
            <pubDate>Wed, 22 May 2019 11:34:56 GMT</pubDate>
            <atom:updated>2019-05-22T11:34:56.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*rA2MOCW4-ypY3GY_WUGXWA.jpeg" /></figure><p>We recently concluded a very interesting and challenging consulting engagement for one our customers in North America. While we have automated several GKE deployments using Terraform in the past, this one was a bit extra interesting — because it involved deploying self managed kubernetes clusters on VMs, on GCE. Why self managed? For greater control, obviously. You can find more details below.</p><h3>Limitations that we overcame with deploying Kubernetes on GCE</h3><ul><li>Flexibility to use custom images for deployments</li><li>Full control over the master node</li><li>Access to deep level elements of the cluster</li><li>Additional customization to Kubernetes cluster</li><li>Choice of Container Networking Interface(CNI)</li><li>Easy upgrade or downgrade of Kubernetes version</li></ul><p>Well now, It is evident that the following question pops up when you read the title of this blog.</p><blockquote>“<strong> Isn’t it hard to configure kubernetes manually</strong>?”</blockquote><p>But that’s where the might of Terraform swoops in to save the day. Terraform is an Infrastructure-as-Code powerhouse, that is declarative in nature and can deploy resources to nearly every cloud provider that exists. Hence we utilized terraform to automate our tasks. From creating the infrastructure to deploying kubernetes components, everything was orchestrated with Terraform.</p><p>Before diving into deploying this architecture, let us have a look into the features that it provides:</p><ul><li>Horizontal pods autoscaling</li><li>Cluster Autoscaling</li><li>Calico CNI</li><li>GPU provisioning</li><li>YAML deployment from terraform</li><li>Prometheus</li></ul><p>Let us begin.</p><h3>Prerequisites</h3><ul><li>Terraform — you can download and install terraform using this <a href="https://www.terraform.io/downloads.html">guide</a>.</li><li>Go — Follow the following steps to install and setup go in your environment.</li></ul><pre><strong>1) Install GO using the following commands:</strong></pre><pre>curl -O <a href="https://storage.googleapis.com/golang/go1.11.2.linux-amd64.tar.gz">https://storage.googleapis.com/golang/go1.11.2.linux-amd64.tar.gz</a><br>tar -xvf go1.11.2.linux-amd64.tar.gz<br>sudo mv go /usr/local</pre><pre><strong>2) Set Go’s root value, which tells Go where to look for its files:</strong></pre><pre>sudo nano ~/.profile</pre><pre><strong>3) Add the below environment variables at the bottom of the profile file:</strong></pre><pre>export GOPATH=$HOME/work<br>export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin</pre><pre><strong>4) Run the below command as well to refresh your profile:</strong></pre><pre>source ~/.profile</pre><pre><strong>5) Verify your installation:</strong></pre><pre>go version</pre><pre><strong>6) Export the GOPATH variable as the installation directory of GO:</strong></pre><pre>export GOPATH=$HOME/work<br>export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin</pre><ul><li>GCP service account json for terraform to authenticate with GCP project.</li></ul><pre><strong>Export the json to </strong><strong>GOOGLE_APPLICATION_CREDENTIALS:</strong></pre><pre>export GOOGLE_APPLICATION_CREDENTIALS=&quot;/path/to/admin-sa-key.json&quot;</pre><ul><li>K8S_manifest terraform provider</li></ul><pre><strong>1) Get this provider on your local system by running below command:</strong></pre><pre>go get -u github.com/searce-engineering/terraform-provider-k8s</pre><pre><strong>NOTE: This will take significant time to get all dependencies required by go for terraform usage</strong></pre><pre><strong>2) Once done create/append the ‘~/.terraformrc’ file with below lines:</strong></pre><pre>providers { k8s = &quot;$GOPATH/bin/terraform-provider-k8s&quot; }</pre><p><strong>Now we are all set!!! Let us initiate deploying the cluster:</strong></p><p><a href="https://github.com/searce-engineering/terraform-k8s-gce">searce-engineering/terraform-k8s-gce</a></p><ul><li>Clone the above repository to get your hands on the terraform script.</li><li>Modify or add the required attributes in the <a href="https://github.com/nikhilkoduri-searce/terraform-k8s-gce/blob/master/terraform.tfvars"><strong>terraform.tfvars</strong></a><strong> </strong>file to customize things such as cluster name, project id, region of the cluster, etc.</li><li>Once you are all set with the attributes of the cluster, we can proceed with deploying the cluster.</li></ul><pre><strong>1) Initialise terraform and download all the plugin:</strong></pre><pre>terraform init</pre><pre><strong>2) Carryout a terraform plan and check if all the resources are being created and have the right attributes on them:</strong></pre><pre>terraform plan</pre><pre><strong>3) Once everything is in place, just deploy it and let terraform do its magic:</strong></pre><pre>terraform apply</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*PkTjbHtjVvRCLOoBRx3XxQ.png" /></figure><p>After it has been successfully applied you can check the gcloud console for the instances that have been created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*FYCNyYLYNmit7tPmAoBZAQ.png" /></figure><p>You can use the following commands to check if all the nodes are joined and ready.</p><pre>kubectl get nodes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*ggMdk3tEVGFiiupl5r7a8w.png" /></figure><p>Now, run the following command to view all the pods in action.</p><pre>kubectl get pods --all-namespaces</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*viiHq0pkWCAIRLUwtkXFlw.png" /></figure><p>Just for my amusement, I deleted the pods of Prometheus deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*faLo8APTkVtGj_Zok0xvLQ.png" /><figcaption>pod deleted</figcaption></figure><p>And just as kubernetes should, kubernetes rises a new pod from the ashes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*AG9ozoOK_TkPUNBiHNQQXw.png" /><figcaption>The new pod is deployed</figcaption></figure><p>Now let us get a deep dive into the Cluster Autoscaler feature of this kubernetes deployment.</p><p><strong>Cluster Autoscaler</strong> is a nifty tool that adjusts the size of the cluster according to the need of the kubernetes deployments. Cluster autoscaler scales up or scales down based on two scenarios:</p><ol><li>The pods are not able to schedule on the nodes due to insufficient resources.</li><li>It scales down when the nodes have been underutilized for a long period of time and its nodes can be scheduled on other nodes</li><li>Adding a similar node to the cluster would help.</li></ol><p>Enough lets experience cluster autoscaler in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*4disPMkDnCfsyq1OaE-Kkg.png" /><figcaption>Initially, there is only one worker node</figcaption></figure><p>As we see currently there are two nodes that are present in the cluster, let us add some load onto the cluster so as to trigger autoscaling. Hence I would be creating 8 replicas of nginx deployment each requesting 500m of CPU.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx<br>  labels:<br>    app: nginx<br>spec:<br>  replicas: 8<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - image: nginx<br>        name: nginx<br>        ports:<br>        - containerPort: 80<br>        resources:<br>          requests:<br>            cpu: &quot;500m&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*_KZMK1IuMJzaqUF69_WSEA.png" /><figcaption>One pod is pending</figcaption></figure><p>And just as the pods are not able to schedule due to insufficient CPU in the existing node. The cluster autoscaler scales the nodes and joins new nodes onto the cluster as you can see in the below screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3oNIlGfebNGMV-QsdA5Zow.png" /><figcaption>Instance template is scaling from 0 to 1</figcaption></figure><p>Before you know it, the new node is up and ready in the cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*PKkr_GVhnqPIGUJcHf0WQw.png" /><figcaption>The new node has been added</figcaption></figure><p>And that all the pending pods get scheduled as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*HPZ07fWZKg_-V8otVTYrLg.png" /></figure><p>Voila!!! We have successfully deployed as well as scaled Kubernetes on GCE using terraform. Happy automation!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d6075cf4d3f" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/kubernetes-deployment-on-google-compute-engine-using-terraform-8d6075cf4d3f">Kubernetes deployment on Google Compute Engine using Terraform</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>