<?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 Akhilesh V A Gopal on Medium]]></title>
        <description><![CDATA[Stories by Akhilesh V A Gopal on Medium]]></description>
        <link>https://medium.com/@akhileshgopal?source=rss-49955bef050e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Yu1OHvHu6ANNjbiaj4sruw.jpeg</url>
            <title>Stories by Akhilesh V A Gopal on Medium</title>
            <link>https://medium.com/@akhileshgopal?source=rss-49955bef050e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:36:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akhileshgopal/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[Auth Proxy Operator — The Secure way of connecting GKE to Cloud SQL]]></title>
            <link>https://blog.thecloudside.com/auth-proxy-operator-the-secure-way-of-connecting-gke-to-cloud-sql-214ba5c1b22e?source=rss-49955bef050e------2</link>
            <guid isPermaLink="false">https://medium.com/p/214ba5c1b22e</guid>
            <category><![CDATA[gke]]></category>
            <category><![CDATA[cloud-sql-proxy]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Akhilesh V A Gopal]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 07:32:08 GMT</pubDate>
            <atom:updated>2023-03-21T07:32:08.142Z</atom:updated>
            <content:encoded><![CDATA[<h3>Achieving Cloud-Native Security: How the Auth Proxy Operator Connects GKE to Cloud SQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a7KkZZU0SksAlEAX2uvGNg.png" /></figure><p>When deploying applications on Google Kubernetes Engine, it’s highly probable that connecting to Cloud SQL will be necessary. Although there are various methods available for connecting application servers with database servers, most of these methods were originally intended for deployment on virtual machines and may seem outdated in a cloud-native environment. However, Google Cloud provides a cloud-native solution <br>for linking the applications running on GKE/GCE to databases hosted on <br>Cloud SQL through the use of Auth Proxy. The following are different types and methods available.</p><p><strong>Cloud SQL Connector</strong>: To connect GKE to Cloud SQL, there are language-specific <a href="https://cloud.google.com/sql/docs/mysql/connect-connectors">Cloud SQL connectors</a> for <a href="https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory">Java</a>, <a href="https://github.com/GoogleCloudPlatform/cloud-sql-python-connector">Python</a>, and <a href="https://github.com/GoogleCloudPlatform/cloud-sql-go-connector">Go</a>. If our application is written in one of those languages, then it’s good to use a Cloud SQL connector.</p><p><strong>Cloud SQL Auth Proxy</strong>: The Cloud SQL Auth proxy provides IAM-based authorization and encryption when connecting to a Cloud SQL instance.</p><p><strong>Cloud SQL Auth Proxy Operator</strong>: The Cloud SQL Auth Proxy Operator is a Kubernetes operator that automates the deployment and management of Cloud SQL Auth Proxy.</p><p>Highlighting the differences between <em>Cloud SQL Connector</em> &amp; <em>Cloud SQL Auth Proxy</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1JvLQHuwFVHeq46WZOeBwA.png" /></figure><p>Highlighting the differences between <em>Cloud SQL Auth Proxy Operator</em> &amp; <em>Cloud SQL Auth Proxy</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HI2PIcOLpMnnZlP2Jh6RrA.png" /></figure><p><strong>Benefits of Auth Proxy Operator :</strong></p><ul><li>The Proxy Operator saves the developer from writing long YAML files.</li><li>Simple configuration of a single Cloud SQL Proxy specific resource — allowing multiple Kubernetes applications to share the same proxy.</li><li>Best practices by default — Google maintains the operator and updates <br>it to the latest recommendations.</li><li>Automatic deployment when the proxy configuration changes.</li><li>Auth proxy operator provides strong encryption and authentication using IAM, which can help keep your database secure.</li></ul><p><strong>Let&#39;s go through setting up Auth Proxy Operator for a sample application</strong></p><p><strong>Pre-requisites</strong> <strong>:</strong></p><ul><li>Cloud SQL instance.</li><li>MySQL database and user account configured on the instance.</li><li>GKE cluster.</li><li>A Sample application that uses MySQL, to be deployed in GKE.</li><li>An IAM service account with Cloud SQL Client role and Log writer role.</li><li>A Kubernetes service account using workload identity.</li></ul><p><em>Cloudshell is used for executing the below commands.</em></p><p><a href="https://cloud.google.com/console/cloudshell/open?git_repo=https://github.com/akhileshgopal/gke-cloudsql-php-repo.git">C<strong><em>lick here</em></strong></a><strong><em> and confirm to clone the Config files of a sample application into your Cloud Shell.</em></strong></p><ul><li>In the Cloud shell, enter the below command to Select a project.<br>[Replace <em>YOUR_PROJECT_ID with the Project ID]</em></li></ul><pre>gcloud config set project [YOUR_PROJECT_ID]</pre><ul><li>Enable the necessary Google Cloud APIs.</li></ul><pre>gcloud services enable compute.googleapis.com sqladmin.googleapis.com \<br>     container.googleapis.com artifactregistry.googleapis.com cloudbuild.googleapis.com</pre><p><strong>Create a Service account</strong></p><ul><li>Create a new service account.</li></ul><pre>gcloud iam service-accounts create php-sa</pre><ul><li>Add the <strong>Cloud SQL Client</strong> role to the service account.</li></ul><p><em>[Replace </em><em>YOUR_PROJECT_IDwith the Project ID]</em></p><pre>gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \<br>  --member=&quot;serviceAccount:php-sa@YOUR_PROJECT_ID.iam.gserviceaccount.com&quot; \<br>  --role=&quot;roles/cloudsql.client&quot;</pre><ul><li>Add the <strong>Cloud SQL Instance User </strong>role to the service account.</li></ul><p><em>[Replace </em><em>YOUR_PROJECT_IDwith the Project ID]</em></p><pre>gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \<br>  --member=&quot;serviceAccount:php-sa@YOUR_PROJECT_ID.iam.gserviceaccount.com&quot; \<br>  --role=&quot;roles/cloudsql.instanceUser&quot;</pre><ul><li>Add the <strong>Log Writer</strong> role to the service account.</li></ul><p><em>[Replace </em><em>YOUR_PROJECT_IDwith the Project ID]</em></p><pre>gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \<br>  --member=&quot;serviceAccount:php-sa@YOUR_PROJECT_ID.iam.gserviceaccount.com&quot; \<br>  --role=&quot;roles/logging.logWriter&quot;</pre><p><strong>Setup Cloud SQL</strong></p><ul><li>Create a Cloud SQL Instance.</li></ul><p><em>[Replace </em>PASSWORD<em>with a password for your MySQL Instance root user]</em></p><pre>gcloud sql instances create php-instance \<br>--database-version=MYSQL_8_0 \<br>--cpu=1 \<br>--memory=4GB \<br>--region=us-central1 \<br>--root-password=PASSWORD \<br>--database-flags=cloudsql_iam_authentication=on</pre><ul><li>Create a Database on the MySQL Instance.</li></ul><pre>gcloud sql databases create phpdb --instance=php-instance</pre><ul><li>Create an IAM user for your MySQL Instance.</li></ul><p><em>[Replace </em>USERNAME<em>with t</em>he email address of your service account<em>]</em></p><pre>gcloud sql users create USERNAME \<br>--instance=php-instance \<br>--type=cloud_iam_service_account</pre><p><strong>Setup Mysql database</strong></p><ul><li>Login to the MySQL Instance.</li></ul><p><em>[Replace </em><em>INSTANCE_IPwith the IP address of MySQL Instance]</em></p><pre>mysql -u root -p -h INSTANCE_IP</pre><ul><li>Select phpdb as the current database.</li></ul><pre>use phpdb</pre><ul><li>Grant all privileges to the database user.</li></ul><pre>GRANT ALL PRIVILEGES ON phpdb.* TO &#39;php-sa&#39;@&#39;%&#39;;</pre><ul><li>Apply privilege changes to the user and exit MySQL Instance.</li></ul><pre>FLUSH PRIVILEGES; exit;</pre><p><strong>Setup GKE Cluster</strong></p><ul><li>Create a GKE cluster</li></ul><p><em>[Replace </em><em>YOUR_PROJECT_IDwith the Project ID]</em></p><pre>gcloud container clusters create &quot;php-cluster&quot; --zone &quot;us-central1-c&quot; --no-enable-basic-auth --scopes &quot;https://www.googleapis.com/auth/cloud-platform&quot; --logging=SYSTEM,WORKLOAD --workload-pool &quot;YOUR_PROJECT_ID.svc.id.goog&quot; --no-enable-master-authorized-networks --machine-type &quot;e2-standard-4&quot; --spot --num-nodes &quot;1&quot;</pre><ul><li>Enable the GKE cluster as the default cluster to be used.</li></ul><pre>gcloud container clusters get-credentials php-cluster \<br>  --zone us-central1-c</pre><p><strong>Setup a Kubernetes service account</strong></p><p>Using the service-account.yaml file, create a <em>Kubernetes service account </em>[php-ksa] configured to have access to Cloud SQL by binding it to the Gcp service account using Workload Identity.</p><ul><li>Run the kubectl apply command in Cloud Shell</li></ul><pre>kubectl apply -f service-account.yaml</pre><ul><li>Enable IAM binding of the Google Cloud Service Account and the Kubernetes Service Account.</li></ul><p><em>Make the following replacements:</em></p><p><em>[</em><em>YOUR_PROJECT_ID with the Project ID , </em>YOUR-K8S-NAMESPACE<em> with </em><em>default ]</em></p><pre>gcloud iam service-accounts add-iam-policy-binding \<br>  --role=&quot;roles/iam.workloadIdentityUser&quot; \<br>  --member=&quot;serviceAccount:YOUR_PROJECT_ID.svc.id.goog[YOUR_K8S_NAMESPACE/php-ksa]&quot; \<br>php-sa@YOUR_PROConclusionJECT_ID.iam.gserviceaccount.com</pre><ul><li>Annotate the Kubernetes Service Account with IAM binding.</li></ul><p><em>[Replace </em><em>YOUR_PROJECT_ID with the Project ID ]</em></p><pre>kubectl annotate serviceaccount \<br>  php-ksa  \<br>  iam.gke.io/gcp-service-account=php-sa@YOUR_PROJECT_ID.iam.gserviceaccount.com</pre><p><strong>Setup Cloud SQL Auth Proxy Operator</strong></p><ul><li>Confirm that kubectl can connect to the cluster.</li></ul><pre>kubectl cluster-info</pre><ul><li>Install the Cloud SQL Auth Proxy Operator into your Kubernetes cluster:</li></ul><pre>curl https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy-operator/v0.2.0/install.sh | bash</pre><ul><li>Wait for the Cloud SQL Auth Proxy Operator to start.</li></ul><pre>kubectl rollout status deployment -n cloud-sql-proxy-operator-system cloud-sql-proxy-operator-controller-manager --timeout=90s</pre><ul><li>Confirm that the operator is installed and running by listing its pods:</li></ul><pre>kubectl get pods -n cloud-sql-proxy-operator-system</pre><p><strong>Deploy a sample app</strong></p><ul><li>Get the Cloud SQL instance connection name.</li></ul><pre>gcloud sql instances describe php-instance --format=&#39;value(connectionName)&#39;</pre><ul><li>Given below is the authproxyworkload.yaml file.</li></ul><p><em>[Replace </em><em>&lt;INSTANCE_CONNECTION_NAME&gt; with instance connection name visible in the Cloud SQL instance overview page]</em></p><pre>apiVersion: cloudsql.cloud.google.com/v1alpha1<br>kind: AuthProxyWorkload<br>metadata:<br>  name: authproxyworkload-sample<br>spec:<br>  workloadSelector:<br>    kind: &quot;Deployment&quot;<br>    name: &quot;php-app&quot;<br>  instances:<br>  - connectionString: &quot;INSTANCE_CONNECTION_NAME&quot;<br>    portEnvName: &quot;PMA_PORT&quot;<br>    hostEnvName: &quot;PMA_HOST&quot;<br>    autoIAMAuthN: true</pre><ul><li>Now apply the proxy configuration to Kubernetes:</li></ul><pre>kubectl apply -f authproxyworkload.yaml</pre><ul><li>Given below is the deployment.yaml file.</li></ul><p><em>[Replace </em><em>YOUR_PROJECT_IDwith the Project ID]</em></p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  annotations:<br>        iam.gke.io/gcp-service-account: php-sa@YOUR_PROJECT_ID.iam.gserviceaccount.com<br>  name: php-app<br>spec:<br>  selector:<br>    matchLabels:<br>      app: php-app<br>  template:<br>    metadata:<br>      labels:<br>        app: php-app<br>    spec:<br>      serviceAccountName: php-ksa<br>      containers:<br>      - name: php-app<br>        image: phpmyadmin<br>        # This app listens on port 80 for web traffic by default.<br>        ports:<br>        - containerPort: 80<br>        env:<br>        - name: PORT<br>          value: &quot;80&quot;<br>        - name: PMA_HOST<br>          value: &quot;set-by-proxy&quot;<br>        - name: PMA_PORT<br>          value: &quot;set-by-proxy&quot;<br>        - name: PMA_PMADB<br>          value: &quot;phpdb&quot;<br>        - name: PMA_USER<br>          value: &quot;php-sa&quot;</pre><ul><li>Now apply the Deployment to Kubernetes cluster:</li></ul><pre>kubectl apply -f deployment.yaml</pre><ul><li>Using the service.yaml file, add a load balancer in the front end of the deployment so that you can access it through the internet:</li></ul><pre>kubectl apply -f service.yaml</pre><ul><li>Now get the details of the running services :</li></ul><pre>kubectl get services</pre><ul><li>Copy the <strong>External IP</strong> address of the load balancer service and paste it on a browser to view the deployed sample app.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aDuuJLSKmyu1KXLHbEebIg.png" /></figure><blockquote>Conclusion</blockquote><p>Cloud SQL Proxy Operator is an open-source Kubernetes operator that automates most of the difficult steps needed to connect a workload in a Kubernetes cluster to Cloud SQL databases.</p><p>The Cloud SQL Auth Proxy Operator makes it easy to add a proxy container to your Kubernetes workloads, configured correctly for production use. The operator introduces a custom resource AuthProxyWorkload, which specifies the Cloud SQL Auth Proxy configuration for a workload. The operator reads this resource and adds a properly configured Cloud SQL Auth Proxy container to the matching workload pods.</p><p>Writing the Kubernetes configuration for a proxy to the production level requires a great deal of deep Kubernetes and proxy knowledge. The Cloud SQL Proxy team has worked to encapsulate that knowledge in this operator. This saves you from having to know all the details to configure your proxy.</p><p>Thank you for reading. I hope you found this helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=214ba5c1b22e" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/auth-proxy-operator-the-secure-way-of-connecting-gke-to-cloud-sql-214ba5c1b22e">Auth Proxy Operator — The Secure way of connecting GKE to Cloud SQL</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>