<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kubernetes &#8211; abdulrahmanuk.com</title>
	<atom:link href="https://www.abdulrahmanuk.com/category/kubernetes/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.abdulrahmanuk.com</link>
	<description>All about Cloud and DevOps</description>
	<lastBuildDate>Mon, 23 Jun 2025 07:37:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.abdulrahmanuk.com/wp-content/uploads/2023/02/icons8-devops-60.png</url>
	<title>Kubernetes &#8211; abdulrahmanuk.com</title>
	<link>https://www.abdulrahmanuk.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled</title>
		<link>https://www.abdulrahmanuk.com/secure-secret-management-in-aks-with-azure-key-vault-csi-driver-and-auto-rotation-enabled/</link>
					<comments>https://www.abdulrahmanuk.com/secure-secret-management-in-aks-with-azure-key-vault-csi-driver-and-auto-rotation-enabled/#respond</comments>
		
		<dc:creator><![CDATA[Abdul Rahman UK]]></dc:creator>
		<pubDate>Mon, 23 Jun 2025 03:06:56 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Exclusive]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<guid isPermaLink="false">https://www.abdulrahmanuk.com/?p=562</guid>

					<description><![CDATA[<p>In today&#8217;s cloud-native environments, securely managing secrets such as database credentials, API tokens, and certificates is vital. For Kubernetes workloads running on Azure Kubernetes Service (AKS), Azure Key Vault provides a highly secure and centralized way to manage secrets. When integrated with the Kubernetes Secrets Store CSI (Container Storage Interface) driver and Azure Workload Identity, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.abdulrahmanuk.com/secure-secret-management-in-aks-with-azure-key-vault-csi-driver-and-auto-rotation-enabled/">Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled</a> appeared first on <a rel="nofollow" href="https://www.abdulrahmanuk.com">abdulrahmanuk.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In today&#8217;s cloud-native environments, securely managing secrets such as database credentials, API tokens, and certificates is vital. For Kubernetes workloads running on Azure Kubernetes Service (AKS), Azure Key Vault provides a highly secure and centralized way to manage secrets. When integrated with the Kubernetes Secrets Store CSI (Container Storage Interface) driver and Azure Workload Identity, secrets can be dynamically and securely injected into pods with automatic rotation support. This blog demonstrates how to set up this integration in a production-grade environment.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f30d.png" alt="🌍" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Use Case Scenario</h2>



<p><strong>Problem:</strong> In most Kubernetes applications, secrets are hardcoded or statically injected, requiring pod restarts when secrets like database passwords are rotated. This creates downtime and maintenance overhead.</p>



<p><strong>Solution:</strong> Integrate AKS with Azure Key Vault using the CSI driver and enable automatic secret rotation. Secrets will be mounted into pods and updated dynamically without restarting the pod, ensuring zero-downtime secret updates.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2699.png" alt="⚙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Architecture Overview</h2>



<p>The architecture includes:</p>



<ul class="wp-block-list">
<li><strong>AKS Cluster</strong></li>



<li><strong>Azure Key Vault</strong></li>



<li><strong>Workload Identity (OIDC)</strong> for secure identity management</li>



<li><strong>CSI Secrets Store Driver</strong> for mounting secrets</li>



<li><strong>Auto-Rotation</strong> of secrets via polling</li>
</ul>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="2560" height="1440" src="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation.png" alt="Secure Secrets Management in AKS with Azure Key Vault CSI Driver and Auto Rotation" class="wp-image-565" title="Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled 1" srcset="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation.png 2560w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-768x432.png 768w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-1536x864.png 1536w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-2048x1152.png 2048w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-150x84.png 150w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-300x169.png 300w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-696x392.png 696w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-1068x601.png 1068w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-1920x1080.png 1920w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/Secure-Secrets-Management-in-AKS-with-Azure-Key-Vault-CSI-Driver-and-Auto-Rotation-600x338.png 600w" sizes="(max-width: 2560px) 100vw, 2560px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4ca.png" alt="📊" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Step-by-Step Implementation</h2>



<p>To create a AKS cluster using CLI please follow this blog: <a href="https://www.abdulrahmanuk.com/aks-cluster-setup-using-azure-cli-with-oidc-azure-key-vault-integration/" data-type="post" data-id="574">AKS Cluster Setup Using Azure CLI with OIDC &amp; Azure Key Vault Integration</a></p>



<h3 class="wp-block-heading">1. Enable OIDC and Workload Identity on exiting AKS cluster</h3>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>az aks update \
  --name &lt;cluster-name> \
  --resource-group &lt;rg> \
  --enable-oidc-issuer \
  --enable-workload-identity
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">az aks update \</span></span>
<span class="line"><span style="color: #A6ACCD">  --name &lt;cluster-name&gt; \</span></span>
<span class="line"><span style="color: #A6ACCD">  --resource-group &lt;rg&gt; \</span></span>
<span class="line"><span style="color: #A6ACCD">  --enable-oidc-issuer \</span></span>
<span class="line"><span style="color: #A6ACCD">  --enable-workload-identity</span></span>
<span class="line"></span></code></pre></div>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="2314" height="1246" src="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6.png" alt="image 6" class="wp-image-579" title="Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled 2" srcset="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6.png 2314w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-768x414.png 768w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-1536x827.png 1536w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-2048x1103.png 2048w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-150x81.png 150w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-300x162.png 300w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-696x375.png 696w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-1068x575.png 1068w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-1920x1034.png 1920w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-6-600x323.png 600w" sizes="(max-width: 2314px) 100vw, 2314px" /></figure>



<p>To enable <strong>Azure Key Vault CSI driver</strong> after the cluster is created:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>az aks enable-addons \
  --addons azure-keyvault-secrets-provider \
  --name &lt;cluster-name> \
  --resource-group &lt;rg>
  </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">az aks enable-addons \</span></span>
<span class="line"><span style="color: #A6ACCD">  --addons azure-keyvault-secrets-provider \</span></span>
<span class="line"><span style="color: #A6ACCD">  --name &lt;cluster-name&gt; \</span></span>
<span class="line"><span style="color: #A6ACCD">  --resource-group &lt;rg&gt;</span></span>
<span class="line"><span style="color: #A6ACCD">  </span></span></code></pre></div>



<p>You can verify through azure portal under your kuberenets cluster dashboard &#8220;Security Configuration&#8221; tab</p>



<figure class="wp-block-image size-full"><img decoding="async" width="2206" height="1168" src="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7.png" alt="image 7" class="wp-image-580" title="Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled 3" srcset="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7.png 2206w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-768x407.png 768w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-1536x813.png 1536w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-2048x1084.png 2048w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-150x79.png 150w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-300x159.png 300w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-696x369.png 696w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-1068x565.png 1068w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-1920x1017.png 1920w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-7-600x318.png 600w" sizes="(max-width: 2206px) 100vw, 2206px" /></figure>



<p>Verify that each node in your cluster&#8217;s node pool has a Secrets Store CSI Driver pod and a Secrets Store Provider Azure pod running</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>kubectl get pods -n kube-system -l 'app in (secrets-store-csi-driver,secrets-store-provider-azure)' -o wide</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">kubectl get pods -n kube-system -l &#39;app in (secrets-store-csi-driver,secrets-store-provider-azure)&#39; -o wide</span></span></code></pre></div>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2560" height="381" src="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-scaled.png" alt="image 8 scaled" class="wp-image-581" title="Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled 4" srcset="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-scaled.png 2560w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-768x114.png 768w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-1536x228.png 1536w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-2048x305.png 2048w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-150x22.png 150w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-300x45.png 300w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-696x104.png 696w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-1068x159.png 1068w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-1920x286.png 1920w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-8-600x89.png 600w" sizes="auto, (max-width: 2560px) 100vw, 2560px" /></figure>



<h3 class="wp-block-heading">1.2 Keyvault creation and configuration</h3>



<p>Create a key vault with Azure role-based access control (Azure RBAC).</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>az keyvault create -n my-demo-k8s-key-vault -g keyvault-demo -l eastus --enable-rbac-authorization</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">az keyvault create -n my-demo-k</span><span style="color: #5DE4C7">8</span><span style="color: #A6ACCD">s-key-vault -g keyvault-demo -l eastus --enable-rbac-authorization</span></span></code></pre></div>



<h3 class="wp-block-heading">2. Create a Managed Identity </h3>



<p>Please export following values on your terminal, make sure you have added your subscription id..etc</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export SUBSCRIPTION_ID=fe4a1fdb-6a1c-4a6d-a6b0-dbb12f6a00f8
export RESOURCE_GROUP=keyvault-demo
export UAMI=azurekeyvaultsecretsprovider-keyvault-demo-cluster
export KEYVAULT_NAME=my-demo-k8s-key-vault
export CLUSTER_NAME=keyvault-demo-cluster

az account set --subscription $SUBSCRIPTION_ID</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">export SUBSCRIPTION_ID=fe</span><span style="color: #5DE4C7">4</span><span style="color: #A6ACCD">a</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD">fdb</span><span style="color: #5DE4C7">-6</span><span style="color: #A6ACCD">a</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD">c</span><span style="color: #5DE4C7">-4</span><span style="color: #A6ACCD">a</span><span style="color: #5DE4C7">6</span><span style="color: #A6ACCD">d-a</span><span style="color: #5DE4C7">6</span><span style="color: #A6ACCD">b</span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD">-dbb</span><span style="color: #5DE4C7">12</span><span style="color: #A6ACCD">f</span><span style="color: #5DE4C7">6</span><span style="color: #A6ACCD">a</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD">f</span><span style="color: #5DE4C7">8</span></span>
<span class="line"><span style="color: #A6ACCD">export RESOURCE_GROUP=keyvault-demo</span></span>
<span class="line"><span style="color: #A6ACCD">export UAMI=azurekeyvaultsecretsprovider-keyvault-demo-cluster</span></span>
<span class="line"><span style="color: #A6ACCD">export KEYVAULT_NAME=my-demo-k</span><span style="color: #5DE4C7">8</span><span style="color: #A6ACCD">s-key-vault</span></span>
<span class="line"><span style="color: #A6ACCD">export CLUSTER_NAME=keyvault-demo-cluster</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A6ACCD">az account set --subscription $SUBSCRIPTION_ID</span></span></code></pre></div>



<p>To Create a managed identity, following azure cli command</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>az identity create --name $UAMI --resource-group $RESOURCE_GROUP

export USER_ASSIGNED_CLIENT_ID="$(az identity show -g $RESOURCE_GROUP --name $UAMI --query 'clientId' -o tsv)"

export IDENTITY_TENANT=$(az aks show --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --query identity.tenantId -o tsv)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">az identity create --name $UAMI --resource-group $RESOURCE_GROUP</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A6ACCD">export USER_ASSIGNED_CLIENT_ID=</span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">$(az identity show -g $RESOURCE_GROUP --name $UAMI --query &#39;clientId&#39; -o tsv)</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A6ACCD">export IDENTITY_TENANT=$(az aks show --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --query identity.tenantId -o tsv)</span></span></code></pre></div>



<p>Create a role assignment that grants the workload ID access the key vault</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export KEYVAULT_SCOPE=$(az keyvault show --name $KEYVAULT_NAME --query id -o tsv)

az role assignment create --role "Key Vault Administrator" --assignee $USER_ASSIGNED_CLIENT_ID --scope $KEYVAULT_SCOPE</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">export KEYVAULT_SCOPE=$(az keyvault show --name $KEYVAULT_NAME --query id -o tsv)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A6ACCD">az role assignment create --role </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">Key Vault Administrator</span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD"> --assignee $USER_ASSIGNED_CLIENT_ID --scope $KEYVAULT_SCOPE</span></span></code></pre></div>



<p>Get the AKS cluster OIDC Issuer URL</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export AKS_OIDC_ISSUER="$(az aks show --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --query "oidcIssuerProfile.issuerUrl" -o tsv)"

echo $AKS_OIDC_ISSUER</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">export AKS_OIDC_ISSUER=</span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">$(az aks show --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --query </span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD">oidcIssuerProfile.issuerUrl</span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7"> -o tsv)</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #A6ACCD">echo $AKS_OIDC_ISSUER</span></span></code></pre></div>



<h3 class="wp-block-heading">3. Annotate Kubernetes ServiceAccount</h3>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export SERVICE_ACCOUNT_NAME="workload-identity-sa"
export SERVICE_ACCOUNT_NAMESPACE="default" </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">export SERVICE_ACCOUNT_NAME=</span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">workload-identity-sa</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">export SERVICE_ACCOUNT_NAMESPACE=</span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">default</span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD"> </span></span></code></pre></div>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>cat &lt;&lt;EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
  name: ${SERVICE_ACCOUNT_NAME}
  namespace: ${SERVICE_ACCOUNT_NAMESPACE}
  annotations:
    azure.workload.identity/client-id: "${USER_ASSIGNED_CLIENT_ID}"
EOF
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">cat &lt;&lt;EOF | kubectl apply -f -</span></span>
<span class="line"><span style="color: #A6ACCD">apiVersion: v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: ServiceAccount</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: ${</span><span style="color: #D0679D">SERVICE_ACCOUNT_NAME</span><span style="color: #A6ACCD">}</span></span>
<span class="line"><span style="color: #A6ACCD">  namespace: ${</span><span style="color: #D0679D">SERVICE_ACCOUNT_NAMESPACE</span><span style="color: #A6ACCD">}</span></span>
<span class="line"><span style="color: #A6ACCD">  annotations:</span></span>
<span class="line"><span style="color: #A6ACCD">    azure.workload.identity/client-id: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">${USER_ASSIGNED_CLIENT_ID}</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">EOF</span></span>
<span class="line"></span></code></pre></div>



<p>Or If above syntax confusing, SA direct yaml syntax given below fill details accordingly </p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>apiVersion: v1
kind: ServiceAccount
metadata:
  name: workload-identity-sa
  annotations:
    azure.workload.identity/client-id: &lt;your-client-id>
    namespace: default</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">apiVersion: v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: ServiceAccount</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: workload-identity-sa</span></span>
<span class="line"><span style="color: #A6ACCD">  annotations:</span></span>
<span class="line"><span style="color: #A6ACCD">    azure.workload.identity/client-id: &lt;your-client-id&gt;</span></span>
<span class="line"><span style="color: #A6ACCD">    namespace: default</span></span></code></pre></div>



<p>Setup Federation</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export FEDERATED_IDENTITY_NAME="aksfederatedidentity" 

az identity federated-credential create --name $FEDERATED_IDENTITY_NAME --identity-name $UAMI --resource-group $RESOURCE_GROUP --issuer ${AKS_OIDC_ISSUER} --subject system:serviceaccount:${SERVICE_ACCOUNT_NAMESPACE}:${SERVICE_ACCOUNT_NAME}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">export FEDERATED_IDENTITY_NAME=</span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">aksfederatedidentity</span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD"> </span></span>
<span class="line"></span>
<span class="line"><span style="color: #A6ACCD">az identity federated-credential create --name $FEDERATED_IDENTITY_NAME --identity-name $UAMI --resource-group $RESOURCE_GROUP --issuer ${</span><span style="color: #D0679D">AKS_OIDC_ISSUER</span><span style="color: #A6ACCD">} --subject system:serviceaccount:${</span><span style="color: #D0679D">SERVICE_ACCOUNT_NAMESPACE</span><span style="color: #A6ACCD">}:${</span><span style="color: #D0679D">SERVICE_ACCOUNT_NAME</span><span style="color: #A6ACCD">}</span></span></code></pre></div>



<h3 class="wp-block-heading">4. Create SecretProviderClass</h3>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>cat &lt;&lt;EOF | kubectl apply -f -
# This is a SecretProviderClass example using workload identity to access your key vault
apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
  name: azure-kvname-wi # needs to be unique per namespace
spec:
  provider: azure
  parameters:
    usePodIdentity: "false"
    clientID: "${USER_ASSIGNED_CLIENT_ID}" # Setting this to use workload identity
    keyvaultName: ${KEYVAULT_NAME}       # Set to the name of your key vault
    cloudName: ""                         # [OPTIONAL for Azure] if not provided, the Azure environment defaults to AzurePublicCloud
    objects:  |
      array:
        - |
          objectName: DB-Password         # Set to the name of your secret
          objectType: secret              # object types: secret, key, or cert
          objectVersion: ""              
    tenantId: "${IDENTITY_TENANT}"        # The tenant ID of the key vault
EOF</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">cat &lt;&lt;EOF | kubectl apply -f -</span></span>
<span class="line"><span style="color: #A6ACCD"># This is a SecretProviderClass example using workload identity to access your key vault</span></span>
<span class="line"><span style="color: #A6ACCD">apiVersion: secrets-store.csi.x-k</span><span style="color: #5DE4C7">8</span><span style="color: #A6ACCD">s.io/v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: SecretProviderClass</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: azure-kvname-wi # needs to be unique per namespace</span></span>
<span class="line"><span style="color: #A6ACCD">spec:</span></span>
<span class="line"><span style="color: #A6ACCD">  provider: azure</span></span>
<span class="line"><span style="color: #A6ACCD">  parameters:</span></span>
<span class="line"><span style="color: #A6ACCD">    usePodIdentity: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">false</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    clientID: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">${USER_ASSIGNED_CLIENT_ID}</span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD"> # Setting this to use workload identity</span></span>
<span class="line"><span style="color: #A6ACCD">    keyvaultName: ${</span><span style="color: #D0679D">KEYVAULT_NAME</span><span style="color: #A6ACCD">}       # Set to the name of your key vault</span></span>
<span class="line"><span style="color: #A6ACCD">    cloudName: </span><span style="color: #A6ACCD">&quot;&quot;</span><span style="color: #A6ACCD">                         # [</span><span style="color: #D0679D">OPTIONAL</span><span style="color: #A6ACCD"> </span><span style="color: #D0679D">for</span><span style="color: #A6ACCD"> </span><span style="color: #D0679D">Azure</span><span style="color: #A6ACCD">] if not provided, the Azure environment defaults to AzurePublicCloud</span></span>
<span class="line"><span style="color: #A6ACCD">    objects:  |</span></span>
<span class="line"><span style="color: #A6ACCD">      array:</span></span>
<span class="line"><span style="color: #A6ACCD">        - |</span></span>
<span class="line"><span style="color: #A6ACCD">          objectName: DB-Password         # Set to the name of your secret</span></span>
<span class="line"><span style="color: #A6ACCD">          objectType: secret              # object types: secret, key, or cert</span></span>
<span class="line"><span style="color: #A6ACCD">          objectVersion: </span><span style="color: #A6ACCD">&quot;&quot;</span><span style="color: #A6ACCD">              </span></span>
<span class="line"><span style="color: #A6ACCD">    tenantId: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">${IDENTITY_TENANT}</span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD">        # The tenant ID of the key vault</span></span>
<span class="line"><span style="color: #A6ACCD">EOF</span></span></code></pre></div>



<p>Or use below direct yaml secretproviderclass and fill details accordingly</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
  name: azure-kvname-wi
spec:
  provider: azure
  parameters:
    keyvaultName: &lt;your-kv-name>
    tenantId: &lt;your-tenant-id>
    clientID: &lt;your-client-id>
    objects: |
      array:
        - objectName: DB-Password
          objectType: secret
          objectVersion: ""
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">apiVersion: secrets-store.csi.x-k</span><span style="color: #5DE4C7">8</span><span style="color: #A6ACCD">s.io/v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: SecretProviderClass</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: azure-kvname-wi</span></span>
<span class="line"><span style="color: #A6ACCD">spec:</span></span>
<span class="line"><span style="color: #A6ACCD">  provider: azure</span></span>
<span class="line"><span style="color: #A6ACCD">  parameters:</span></span>
<span class="line"><span style="color: #A6ACCD">    keyvaultName: &lt;your-kv-name&gt;</span></span>
<span class="line"><span style="color: #A6ACCD">    tenantId: &lt;your-tenant-id&gt;</span></span>
<span class="line"><span style="color: #A6ACCD">    clientID: &lt;your-client-id&gt;</span></span>
<span class="line"><span style="color: #A6ACCD">    objects: |</span></span>
<span class="line"><span style="color: #A6ACCD">      array:</span></span>
<span class="line"><span style="color: #A6ACCD">        - objectName: DB-Password</span></span>
<span class="line"><span style="color: #A6ACCD">          objectType: secret</span></span>
<span class="line"><span style="color: #A6ACCD">          objectVersion: </span><span style="color: #A6ACCD">&quot;&quot;</span></span>
<span class="line"></span></code></pre></div>



<h3 class="wp-block-heading">5. Deploy a Workload (e.g., BusyBox Test Pod)</h3>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox-secrets
spec:
  replicas: 1
  selector:
    matchLabels:
      app: busybox-secrets
  template:
    metadata:
      labels:
        app: busybox-secrets
        azure.workload.identity/use: "true"
    spec:
      serviceAccountName: workload-identity-sa
      containers:
        - name: busybox
          image: registry.k8s.io/e2e-test-images/busybox:1.29-4
          command: ["/bin/sleep", "10000"]
          volumeMounts:
            - name: secrets-store-vol
              mountPath: "/mnt/secrets-store"
              readOnly: true
      volumes:
        - name: secrets-store-vol
          csi:
            driver: secrets-store.csi.k8s.io
            readOnly: true
            volumeAttributes:
              secretProviderClass: azure-kvname-wi
              rotationPollInterval: "30s"
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">apiVersion: apps/v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: Deployment</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: busybox-secrets</span></span>
<span class="line"><span style="color: #A6ACCD">spec:</span></span>
<span class="line"><span style="color: #A6ACCD">  replicas: </span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">  selector:</span></span>
<span class="line"><span style="color: #A6ACCD">    matchLabels:</span></span>
<span class="line"><span style="color: #A6ACCD">      app: busybox-secrets</span></span>
<span class="line"><span style="color: #A6ACCD">  template:</span></span>
<span class="line"><span style="color: #A6ACCD">    metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">      labels:</span></span>
<span class="line"><span style="color: #A6ACCD">        app: busybox-secrets</span></span>
<span class="line"><span style="color: #A6ACCD">        azure.workload.identity/use: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">true</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    spec:</span></span>
<span class="line"><span style="color: #A6ACCD">      serviceAccountName: workload-identity-sa</span></span>
<span class="line"><span style="color: #A6ACCD">      containers:</span></span>
<span class="line"><span style="color: #A6ACCD">        - name: busybox</span></span>
<span class="line"><span style="color: #A6ACCD">          image: registry.k</span><span style="color: #5DE4C7">8</span><span style="color: #A6ACCD">s.io/e</span><span style="color: #5DE4C7">2</span><span style="color: #A6ACCD">e-test-images/busybox:</span><span style="color: #5DE4C7">1.29-4</span></span>
<span class="line"><span style="color: #A6ACCD">          command: [</span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">/bin/sleep</span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD">, </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">10000</span><span style="color: #A6ACCD">&quot;</span><span style="color: #A6ACCD">]</span></span>
<span class="line"><span style="color: #A6ACCD">          volumeMounts:</span></span>
<span class="line"><span style="color: #A6ACCD">            - name: secrets-store-vol</span></span>
<span class="line"><span style="color: #A6ACCD">              mountPath: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">/mnt/secrets-store</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">              readOnly: </span><span style="color: #5DE4C7">true</span></span>
<span class="line"><span style="color: #A6ACCD">      volumes:</span></span>
<span class="line"><span style="color: #A6ACCD">        - name: secrets-store-vol</span></span>
<span class="line"><span style="color: #A6ACCD">          csi:</span></span>
<span class="line"><span style="color: #A6ACCD">            driver: secrets-store.csi.k</span><span style="color: #5DE4C7">8</span><span style="color: #A6ACCD">s.io</span></span>
<span class="line"><span style="color: #A6ACCD">            readOnly: </span><span style="color: #5DE4C7">true</span></span>
<span class="line"><span style="color: #A6ACCD">            volumeAttributes:</span></span>
<span class="line"><span style="color: #A6ACCD">              secretProviderClass: azure-kvname-wi</span></span>
<span class="line"><span style="color: #A6ACCD">              rotationPollInterval: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">30s</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"></span></code></pre></div>



<p>Now you can exec into the pod and verify the secret are mounted into the container. You can run following command to verify the same</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2374" height="296" src="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9.png" alt="image 9" class="wp-image-582" title="Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled 5" srcset="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9.png 2374w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-768x96.png 768w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-1536x192.png 1536w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-2048x255.png 2048w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-150x19.png 150w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-300x37.png 300w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-696x87.png 696w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-1068x133.png 1068w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-1920x239.png 1920w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-9-600x75.png 600w" sizes="auto, (max-width: 2374px) 100vw, 2374px" /></figure>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>kubectl exec &lt;pod> -- ls /mnt/secrets-store/
kubectl exec &lt;pod> -- cat /mnt/secrets-store/DB-Password</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">kubectl exec &lt;pod&gt; -- ls /mnt/secrets-store/</span></span>
<span class="line"><span style="color: #A6ACCD">kubectl exec &lt;pod&gt; -- cat /mnt/secrets-store/DB-Password</span></span></code></pre></div>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">⟳ Enable Auto-Rotation of Secrets</h2>



<p>Run the following command to enable the rotation feature:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>az aks addon update \
  --resource-group &lt;rg> \
  --name &lt;cluster-name> \
  --addon azure-keyvault-secrets-provider \
  --enable-secret-rotation \
  --rotation-poll-interval 30s
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">az aks addon update \</span></span>
<span class="line"><span style="color: #A6ACCD">  --resource-group &lt;rg&gt; \</span></span>
<span class="line"><span style="color: #A6ACCD">  --name &lt;cluster-name&gt; \</span></span>
<span class="line"><span style="color: #A6ACCD">  --addon azure-keyvault-secrets-provider \</span></span>
<span class="line"><span style="color: #A6ACCD">  --enable-secret-rotation \</span></span>
<span class="line"><span style="color: #A6ACCD">  --rotation-poll-interval </span><span style="color: #5DE4C7">30</span><span style="color: #A6ACCD">s</span></span>
<span class="line"></span></code></pre></div>



<p>Verify it with:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>kubectl -n kube-system describe ds aks-secrets-store-csi-driver
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">kubectl -n kube-system describe ds aks-secrets-store-csi-driver</span></span>
<span class="line"></span></code></pre></div>



<p>Ensure the arguments include:</p>



<ul class="wp-block-list">
<li><code>--enable-secret-rotation=true</code></li>



<li><code>--rotation-poll-interval=30s</code></li>
</ul>



<p>To work Azure Key Vault auto rotation in deployment, Make sure following settings are there in first</p>



<p>1) Under SecretProviderClass Leave <code>objectVersion</code> blank</p>



<p>2) Add to volume attributes on deployment file: rotationPollInterval</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>volumeAttributes:
  secretProviderClass: azure-kvname-wi
  rotationPollInterval: "30s"</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">volumeAttributes:</span></span>
<span class="line"><span style="color: #A6ACCD">  secretProviderClass: azure-kvname-wi</span></span>
<span class="line"><span style="color: #A6ACCD">  rotationPollInterval: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">30s</span><span style="color: #A6ACCD">&quot;</span></span></code></pre></div>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f50d.png" alt="🔍" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Testing the Rotation</h2>



<ol class="wp-block-list">
<li>Manually update the secret version in Azure Key Vault.</li>



<li>Wait for <code>rotationPollInterval</code>.</li>



<li>Check the mounted file inside the pod:</li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>kubectl exec &lt;pod> -- ls /mnt/secrets-store/
kubectl exec &lt;pod> -- cat /mnt/secrets-store/DB-Password</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">kubectl exec &lt;pod&gt; -- ls /mnt/secrets-store/</span></span>
<span class="line"><span style="color: #A6ACCD">kubectl exec &lt;pod&gt; -- cat /mnt/secrets-store/DB-Password</span></span></code></pre></div>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2560" height="113" src="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-scaled.png" alt="image 4 scaled" class="wp-image-577" title="Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled 6" srcset="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-scaled.png 2560w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-768x34.png 768w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-1536x68.png 1536w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-2048x90.png 2048w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-150x7.png 150w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-300x13.png 300w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-696x31.png 696w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-1068x47.png 1068w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-1920x85.png 1920w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-4-600x26.png 600w" sizes="auto, (max-width: 2560px) 100vw, 2560px" /></figure>



<ol start="4" class="wp-block-list">
<li>Observe that the new value is reflected <strong>without restarting</strong> the pod.</li>
</ol>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2560" height="237" src="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-scaled.png" alt="image 5 scaled" class="wp-image-578" title="Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled 7" srcset="https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-scaled.png 2560w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-768x71.png 768w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-1536x142.png 1536w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-2048x190.png 2048w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-150x14.png 150w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-300x28.png 300w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-696x64.png 696w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-1068x99.png 1068w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-1920x178.png 1920w, https://www.abdulrahmanuk.com/wp-content/uploads/2025/06/image-5-600x56.png 600w" sizes="auto, (max-width: 2560px) 100vw, 2560px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4d7.png" alt="📗" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Best Practices</h2>



<ul class="wp-block-list">
<li>Avoid <code>subPath</code> in volume mounts (breaks rotation).</li>



<li>Ensure your application <strong>reads secrets from file</strong>, not env vars.</li>



<li>Consider implementing <strong>file watchers</strong> for dynamic config reloads.</li>



<li>Monitor CSI driver logs: <code>kubectl logs ds/aks-secrets-store-csi-driver -n kube-system</code></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f31f.png" alt="🌟" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Conclusion</h2>



<p>With Azure Key Vault, CSI driver, and workload identity, you can achieve secure, automated, and zero-downtime secret management for your AKS workloads. Auto-rotation ensures credentials like DB passwords can be updated without disrupting live applications.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Feel free to follow me on <a href="https://www.linkedin.com/in/abdul-rahman-uk/" rel="nofollow noopener" target="_blank">LinkedIn</a> and share your thoughts. For a complete YAML reference or demo repo, connect with me or leave a comment!</p>
</blockquote>
<p>The post <a rel="nofollow" href="https://www.abdulrahmanuk.com/secure-secret-management-in-aks-with-azure-key-vault-csi-driver-and-auto-rotation-enabled/">Secure Secret Management in AKS with Azure Key Vault CSI Driver and Auto-Rotation Enabled</a> appeared first on <a rel="nofollow" href="https://www.abdulrahmanuk.com">abdulrahmanuk.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.abdulrahmanuk.com/secure-secret-management-in-aks-with-azure-key-vault-csi-driver-and-auto-rotation-enabled/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kubernetes Resource Limits Simplified – From Beginner to Production Ready</title>
		<link>https://www.abdulrahmanuk.com/kubernetes-resource-limits-simplified-from-beginner-to-production-ready/</link>
					<comments>https://www.abdulrahmanuk.com/kubernetes-resource-limits-simplified-from-beginner-to-production-ready/#respond</comments>
		
		<dc:creator><![CDATA[Abdul Rahman UK]]></dc:creator>
		<pubDate>Sun, 15 Jun 2025 13:08:20 +0000</pubDate>
				<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[devops]]></category>
		<guid isPermaLink="false">https://www.abdulrahmanuk.com/?p=545</guid>

					<description><![CDATA[<p>In the world of Kubernetes, managing resources wisely is key to keeping your cluster healthy and your workloads running smoothly. Without proper controls, one application can easily consume more than its fair share of CPU, memory, or pods, leading to resource contention and system instability. Thankfully, Kubernetes provides powerful tools to enforce resource limits at [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.abdulrahmanuk.com/kubernetes-resource-limits-simplified-from-beginner-to-production-ready/">Kubernetes Resource Limits Simplified – From Beginner to Production Ready</a> appeared first on <a rel="nofollow" href="https://www.abdulrahmanuk.com">abdulrahmanuk.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In the world of <strong>Kubernetes</strong>, managing resources wisely is key to keeping your cluster healthy and your workloads running smoothly. Without proper controls, one application can easily consume more than its fair share of CPU, memory, or pods, leading to resource contention and system instability.</p>



<p>Thankfully, Kubernetes provides powerful tools to enforce <strong>resource limits at the namespace level</strong>, allowing teams to share the cluster fairly. In this blog post, we’ll explore two important tools for namespace-level resource management:</p>



<ul class="wp-block-list">
<li><strong>Resource Quotas</strong></li>



<li><strong>Limit Ranges</strong></li>
</ul>



<p>Let’s dive in and see how they work, with practical examples to help you get started.</p>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f539.png" alt="🔹" class="wp-smiley" style="height: 1em; max-height: 1em;" /> What Are Resource Quotas in Kubernetes?</h2>



<p><strong>Resource Quotas</strong> let administrators cap the total amount of resources that a specific namespace can use. Think of it as setting a budget for pods, CPU, memory, and other compute resources.</p>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4cc.png" alt="📌" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Why Use Resource Quotas?</h3>



<ul class="wp-block-list">
<li>Define clear usage boundaries per namespace.</li>



<li>Monitor and track resource usage in real-time.</li>



<li>Automatically block workloads that try to exceed their limits.</li>
</ul>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f6e0.png" alt="🛠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> How to Set a Resource Quota</h3>



<p>To apply a Resource Quota, create a YAML file and apply it to the relevant namespace.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><textarea class="code-block-pro-copy-button-textarea" aria-hidden="true" readonly>apiVersion: v1
kind: ResourceQuota
metadata:
  name: resource-quota-example
  namespace: example-namespace
spec:
  hard:
    pods: &#8220;1&#8221;
    requests.cpu: &#8220;2&#8221;
    requests.memory: &#8220;5Gi&#8221;
    limits.cpu: &#8220;4&#8221;
    limits.memory: &#8220;10Gi&#8221;</textarea><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">apiVersion: v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: ResourceQuota</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: resource-quota-example</span></span>
<span class="line"><span style="color: #A6ACCD">  namespace: example-namespace</span></span>
<span class="line"><span style="color: #A6ACCD">spec:</span></span>
<span class="line"><span style="color: #A6ACCD">  hard:</span></span>
<span class="line"><span style="color: #A6ACCD">    pods: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    requests.cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">2</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    requests.memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">5Gi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    limits.cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">4</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    limits.memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">10Gi</span><span style="color: #A6ACCD">&quot;</span></span></code></pre></div>



<p>Then apply it using:</p>



<pre class="wp-block-code"><code>kubectl apply -f resource-quota.yaml</code></pre>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> This will limit the <code>example-namespace</code> to <strong>1 pod</strong>, <strong>2 CPU requests</strong>, <strong>5Gi of memory requests</strong>, and caps CPU and memory usage at <strong>4 CPUs</strong> and <strong>10Gi</strong>, respectively.</p>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Verifying the Resource Quota</h3>



<p>Check if the quota has been successfully applied:</p>



<pre class="wp-block-code"><code>kubectl get resourcequota resource-quota-example -n example-namespace</code></pre>



<p>Or to get detailed info:</p>



<pre class="wp-block-code"><code>kubectl describe ns example-namespace</code></pre>



<p>Sample output:</p>



<pre class="wp-block-preformatted">Resource         Used  Hard<br>limits.cpu       0     4<br>limits.memory    0     10Gi<br>pods             0     1<br>requests.cpu     0     2<br>requests.memory  0     5Gi</pre>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f50d.png" alt="🔍" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Testing Quota Enforcement</h3>



<p>Let’s try deploying more pods than allowed to see the quota in action.</p>



<p><strong>Deployment with 2 replicas (but the quota allows only 1):</strong></p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><textarea class="code-block-pro-copy-button-textarea" aria-hidden="true" readonly>apiVersion: apps/v1
kind: Deployment
metadata:
  name: quota-test
  namespace: example-namespace
  labels:
    app: deployment-label
spec:
  replicas: 2
  selector:
    matchLabels:
      app: deployment-label
  template:
    metadata:
      labels:
        app: deployment-label
    spec:
      containers:
      &#8211; name: nginx-deploy
        image: nginx:latest
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
          limits:
            cpu: 100m
            memory: 100Mi</textarea><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">apiVersion: apps/v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: Deployment</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: quota-test</span></span>
<span class="line"><span style="color: #A6ACCD">  namespace: example-namespace</span></span>
<span class="line"><span style="color: #A6ACCD">  labels:</span></span>
<span class="line"><span style="color: #A6ACCD">    app: deployment-label</span></span>
<span class="line"><span style="color: #A6ACCD">spec:</span></span>
<span class="line"><span style="color: #A6ACCD">  replicas: </span><span style="color: #5DE4C7">2</span></span>
<span class="line"><span style="color: #A6ACCD">  selector:</span></span>
<span class="line"><span style="color: #A6ACCD">    matchLabels:</span></span>
<span class="line"><span style="color: #A6ACCD">      app: deployment-label</span></span>
<span class="line"><span style="color: #A6ACCD">  template:</span></span>
<span class="line"><span style="color: #A6ACCD">    metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">      labels:</span></span>
<span class="line"><span style="color: #A6ACCD">        app: deployment-label</span></span>
<span class="line"><span style="color: #A6ACCD">    spec:</span></span>
<span class="line"><span style="color: #A6ACCD">      containers:</span></span>
<span class="line"><span style="color: #A6ACCD">      - name: nginx-deploy</span></span>
<span class="line"><span style="color: #A6ACCD">        image: nginx:latest</span></span>
<span class="line"><span style="color: #A6ACCD">        resources:</span></span>
<span class="line"><span style="color: #A6ACCD">          requests:</span></span>
<span class="line"><span style="color: #A6ACCD">            cpu: </span><span style="color: #5DE4C7">100</span><span style="color: #A6ACCD">m</span></span>
<span class="line"><span style="color: #A6ACCD">            memory: </span><span style="color: #5DE4C7">100</span><span style="color: #A6ACCD">Mi</span></span>
<span class="line"><span style="color: #A6ACCD">          limits:</span></span>
<span class="line"><span style="color: #A6ACCD">            cpu: </span><span style="color: #5DE4C7">100</span><span style="color: #A6ACCD">m</span></span>
<span class="line"><span style="color: #A6ACCD">            memory: </span><span style="color: #5DE4C7">100</span><span style="color: #A6ACCD">Mi</span></span></code></pre></div>



<p>Apply the deployment:</p>



<pre class="wp-block-preformatted">kubectl apply -f deploy.yaml<br></pre>



<p>Check the pod status:</p>



<pre class="wp-block-preformatted">kubectl get all -n example-namespace<br></pre>



<p>ou’ll see something like:</p>



<pre class="wp-block-preformatted">Warning  FailedCreate  pods "quota-test-xxxx" is forbidden: exceeded quota: resource-quota-example...</pre>



<p>The second pod fails to start—<strong>exactly what we want</strong>. The quota is working as intended!</p>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f539.png" alt="🔹" class="wp-smiley" style="height: 1em; max-height: 1em;" /> What Are Limit Ranges in Kubernetes?</h2>



<p>While Resource Quotas set overall namespace limits, <strong>Limit Ranges</strong> control the <strong>default and maximum/minimum resource limits for each pod, container, or PVC</strong>. This ensures no single pod or container hogs cluster resources.</p>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4cc.png" alt="📌" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Why Use Limit Ranges?</h3>



<ul class="wp-block-list">
<li>Enforce consistent resource consumption across deployments.</li>



<li>Prevent resource abuse by setting sensible defaults.</li>



<li>Ensure all pods have a minimum allocation for healthy operation.</li>
</ul>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f6e0.png" alt="🛠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> How to Set a Limit Range</h3>



<p>Create a <code>limit-range.yaml</code> file:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><textarea class="code-block-pro-copy-button-textarea" aria-hidden="true" readonly>apiVersion: v1
kind: LimitRange
metadata:
  name: limit-range-example
  namespace: example-namespace
spec:
  limits:
  &#8211; type: Pod
    max:
      cpu: &#8220;2&#8221;
      memory: &#8220;4Gi&#8221;
    min:
      cpu: &#8220;200m&#8221;
      memory: &#8220;256Mi&#8221;
    maxLimitRequestRatio:
      cpu: &#8220;4&#8221;
      memory: &#8220;8&#8221;
  &#8211; type: Container
    default:
      cpu: &#8220;500m&#8221;
      memory: &#8220;512Mi&#8221;
    defaultRequest:
      cpu: &#8220;250m&#8221;
      memory: &#8220;256Mi&#8221;
    max:
      cpu: &#8220;1&#8221;
      memory: &#8220;1Gi&#8221;
    min:
      cpu: &#8220;100m&#8221;
      memory: &#8220;128Mi&#8221;
    maxLimitRequestRatio:
      cpu: &#8220;2&#8221;
      memory: &#8220;4&#8221;
  &#8211; type: PersistentVolumeClaim
    max:
      storage: &#8220;10Gi&#8221;
    min:
      storage: &#8220;1Gi&#8221;
    default:
      storage: &#8220;5Gi&#8221;
    defaultRequest:
      storage: &#8220;2Gi&#8221;
    maxLimitRequestRatio:
      storage: &#8220;2&#8221;</textarea><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">apiVersion: v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: LimitRange</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: limit-range-example</span></span>
<span class="line"><span style="color: #A6ACCD">  namespace: example-namespace</span></span>
<span class="line"><span style="color: #A6ACCD">spec:</span></span>
<span class="line"><span style="color: #A6ACCD">  limits:</span></span>
<span class="line"><span style="color: #A6ACCD">  - type: Pod</span></span>
<span class="line"><span style="color: #A6ACCD">    max:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">2</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">4Gi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    min:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">200m</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">256Mi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    maxLimitRequestRatio:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">4</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">8</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">  - type: Container</span></span>
<span class="line"><span style="color: #A6ACCD">    default:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">500m</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">512Mi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    defaultRequest:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">250m</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">256Mi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    max:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">1Gi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    min:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">100m</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">128Mi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    maxLimitRequestRatio:</span></span>
<span class="line"><span style="color: #A6ACCD">      cpu: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">2</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">      memory: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">4</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">  - type: PersistentVolumeClaim</span></span>
<span class="line"><span style="color: #A6ACCD">    max:</span></span>
<span class="line"><span style="color: #A6ACCD">      storage: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">10Gi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    min:</span></span>
<span class="line"><span style="color: #A6ACCD">      storage: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">1Gi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    default:</span></span>
<span class="line"><span style="color: #A6ACCD">      storage: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">5Gi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    defaultRequest:</span></span>
<span class="line"><span style="color: #A6ACCD">      storage: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">2Gi</span><span style="color: #A6ACCD">&quot;</span></span>
<span class="line"><span style="color: #A6ACCD">    maxLimitRequestRatio:</span></span>
<span class="line"><span style="color: #A6ACCD">      storage: </span><span style="color: #A6ACCD">&quot;</span><span style="color: #5DE4C7">2</span><span style="color: #A6ACCD">&quot;</span></span></code></pre></div>



<p>Apply it:</p>



<pre class="wp-block-preformatted"><code>kubectl apply -f limit-range.yaml<br></code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f9e0.png" alt="🧠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Limit Ranges apply defaults <em>automatically</em> to pods if you forget to specify them!</p>
</blockquote>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Verifying the Limit Range</h3>



<p>Use the following commands:</p>



<pre class="wp-block-preformatted">kubectl describe limitrange limit-range-example -n example-namespace<br>kubectl describe ns example-namespace</pre>



<p>You’ll see something like:</p>



<pre class="wp-block-preformatted">Type                   Resource  Min    Max   Default Request  Default Limit  Max Limit/Request Ratio<br>Pod                    cpu       200m   2     -                -              4<br>Pod                    memory    256Mi  4Gi   -                -              8<br>Container              cpu       100m   1     250m             500m           2<br>Container              memory    128Mi  1Gi   256Mi            512Mi          4<br>PersistentVolumeClaim  storage   1Gi    10Gi  2Gi              5Gi            2</pre>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f50d.png" alt="🔍" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Testing the Limit Range in Action</h3>



<p>Create a deployment <strong>without resource specs</strong> and watch the defaults kick in:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#a6accd;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1b1e28"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#a6accd;display:none" aria-label="Copy" class="code-block-pro-copy-button"><textarea class="code-block-pro-copy-button-textarea" aria-hidden="true" readonly>apiVersion: apps/v1
kind: Deployment
metadata:
  name: limit-test
  namespace: example-namespace
  labels:
    app: deployment-label
spec:
  replicas: 1
  selector:
    matchLabels:
      app: deployment-label
  template:
    metadata:
      labels:
        app: deployment-label
    spec:
      containers:
      &#8211; name: nginx-deploy
        image: nginx:latest</textarea><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki poimandres" style="background-color: #1b1e28" tabindex="0"><code><span class="line"><span style="color: #A6ACCD">apiVersion: apps/v</span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">kind: Deployment</span></span>
<span class="line"><span style="color: #A6ACCD">metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">  name: limit-test</span></span>
<span class="line"><span style="color: #A6ACCD">  namespace: example-namespace</span></span>
<span class="line"><span style="color: #A6ACCD">  labels:</span></span>
<span class="line"><span style="color: #A6ACCD">    app: deployment-label</span></span>
<span class="line"><span style="color: #A6ACCD">spec:</span></span>
<span class="line"><span style="color: #A6ACCD">  replicas: </span><span style="color: #5DE4C7">1</span></span>
<span class="line"><span style="color: #A6ACCD">  selector:</span></span>
<span class="line"><span style="color: #A6ACCD">    matchLabels:</span></span>
<span class="line"><span style="color: #A6ACCD">      app: deployment-label</span></span>
<span class="line"><span style="color: #A6ACCD">  template:</span></span>
<span class="line"><span style="color: #A6ACCD">    metadata:</span></span>
<span class="line"><span style="color: #A6ACCD">      labels:</span></span>
<span class="line"><span style="color: #A6ACCD">        app: deployment-label</span></span>
<span class="line"><span style="color: #A6ACCD">    spec:</span></span>
<span class="line"><span style="color: #A6ACCD">      containers:</span></span>
<span class="line"><span style="color: #A6ACCD">      - name: nginx-deploy</span></span>
<span class="line"><span style="color: #A6ACCD">        image: nginx:latest</span></span></code></pre></div>



<p>Apply it:</p>



<pre class="wp-block-preformatted"><code>kubectl apply -f deploy.yaml<br></code></pre>



<p>Now describe the pod and you&#8217;ll notice the resource requests and limits are automatically applied based on the LimitRange!</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f9e9.png" alt="🧩" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Final Thoughts</h2>



<p><strong>Namespace-level resource control</strong> in Kubernetes is not just a best practice—it’s a necessity for scalable and stable clusters.</p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Use <strong>Resource Quotas</strong> to enforce overall limits per namespace.<br><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Use <strong>Limit Ranges</strong> to set smart defaults and enforce per-container or per-pod limits.</p>



<p>By combining both, you ensure fair resource distribution, avoid noisy neighbor problems, and maintain consistent workload performance across your Kubernetes environment.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4ac.png" alt="💬" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Got questions about resource management in Kubernetes?<br><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4e9.png" alt="📩" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Drop a comment below or connect with me for more DevOps tips and Kubernetes best practices.</p>



<p>Happy Clustering! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f680.png" alt="🚀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p></p>
<p>The post <a rel="nofollow" href="https://www.abdulrahmanuk.com/kubernetes-resource-limits-simplified-from-beginner-to-production-ready/">Kubernetes Resource Limits Simplified – From Beginner to Production Ready</a> appeared first on <a rel="nofollow" href="https://www.abdulrahmanuk.com">abdulrahmanuk.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.abdulrahmanuk.com/kubernetes-resource-limits-simplified-from-beginner-to-production-ready/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AKS Cluster Setup Using Azure CLI with OIDC &#038; Azure Key Vault Integration</title>
		<link>https://www.abdulrahmanuk.com/aks-cluster-setup-using-azure-cli-with-oidc-azure-key-vault-integration/</link>
					<comments>https://www.abdulrahmanuk.com/aks-cluster-setup-using-azure-cli-with-oidc-azure-key-vault-integration/#respond</comments>
		
		<dc:creator><![CDATA[Abdul Rahman UK]]></dc:creator>
		<pubDate>Mon, 23 Jun 2025 01:36:03 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[devops]]></category>
		<guid isPermaLink="false">https://www.abdulrahmanuk.com/?p=574</guid>

					<description><![CDATA[<p>If you&#8217;re more comfortable using the Azure CLI, here&#8217;s how to set up an AKS cluster with Azure Key Vault integration using the Secrets Store CSI Driver, along with OIDC (OpenID Connect) support and Workload Identity. This is especially useful for secure, production-grade Kubernetes deployments. ✅ Step 1: Create an Azure Resource Group This creates [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.abdulrahmanuk.com/aks-cluster-setup-using-azure-cli-with-oidc-azure-key-vault-integration/">AKS Cluster Setup Using Azure CLI with OIDC &amp; Azure Key Vault Integration</a> appeared first on <a rel="nofollow" href="https://www.abdulrahmanuk.com">abdulrahmanuk.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you&#8217;re more comfortable using the <strong>Azure CLI</strong>, here&#8217;s how to set up an <strong>AKS cluster with Azure Key Vault integration</strong> using the <strong>Secrets Store CSI Driver</strong>, along with <strong>OIDC (OpenID Connect) support</strong> and <strong>Workload Identity</strong>. This is especially useful for secure, production-grade Kubernetes deployments.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Step 1: Create an Azure Resource Group</h3>



<pre class="wp-block-code"><code><code>az group create --name keyvault-demo --location eastus
</code></code></pre>



<p>This creates a logical container for your AKS resources.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f680.png" alt="🚀" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Step 2: Create the AKS Cluster with Workload Identity and Azure Key Vault Integration</h3>



<pre class="wp-block-code"><code><code>az aks create \
  --name keyvault-demo-cluster \
  --resource-group keyvault-demo \
  --node-count 1 \
  --enable-addons azure-keyvault-secrets-provider \
  --enable-oidc-issuer \
  --enable-workload-identity
</code></code></pre>



<h4 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2699.png" alt="⚙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Explanation of Flags:</h4>



<ul class="wp-block-list">
<li><code>--enable-addons azure-keyvault-secrets-provider</code>: Installs the CSI driver and Azure Key Vault provider addon.</li>



<li><code>--enable-oidc-issuer</code>: Enables the OIDC issuer URL for secure authentication with federated identity.</li>



<li><code>--enable-workload-identity</code>: Activates Azure Workload Identity (replacement for AAD Pod Identity).</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f510.png" alt="🔐" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Step 3: Get AKS Credentials for kubectl</h3>



<pre class="wp-block-code"><code><code>az aks get-credentials \
  --resource-group keyvault-demo \
  --name keyvault-demo-cluster
</code></code></pre>



<p>This updates your local kubeconfig so you can interact with the new cluster.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f50d.png" alt="🔍" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Step 4: Verify CSI Driver and Azure Provider Pods</h3>



<p>Make sure everything is running correctly:</p>



<pre class="wp-block-code"><code><code>kubectl get pods -n kube-system -l 'app in (secrets-store-csi-driver,secrets-store-provider-azure)' -o wide
</code></code></pre>



<p>You should see pods like:</p>



<ul class="wp-block-list">
<li><code>secrets-store-csi-driver-*</code></li>



<li><code>secrets-store-provider-azure-*</code></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f510.png" alt="🔐" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Bonus: Why Use Azure Key Vault with AKS?</h2>



<ul class="wp-block-list">
<li><strong>Centralized Secrets Management</strong></li>



<li><strong>Automatic Secret Rotation</strong></li>



<li><strong>No Secret Mounting in Code</strong></li>



<li><strong>Secure Identity Binding with Workload Identity</strong></li>
</ul>



<p>This setup is cloud-native, secure, and production-ready.</p>
<p>The post <a rel="nofollow" href="https://www.abdulrahmanuk.com/aks-cluster-setup-using-azure-cli-with-oidc-azure-key-vault-integration/">AKS Cluster Setup Using Azure CLI with OIDC &amp; Azure Key Vault Integration</a> appeared first on <a rel="nofollow" href="https://www.abdulrahmanuk.com">abdulrahmanuk.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.abdulrahmanuk.com/aks-cluster-setup-using-azure-cli-with-oidc-azure-key-vault-integration/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
