title: How to edit/patch kubernetes deployment to add label using python
body: <p>I am fairly new to kubernetes - I have developed web UI/API that automates model deployment using Azure Machine Learning Services to Azure Kubernetes Services (AKS). As a hardening measure, I am tying to set up managed identity for deployed pods in AKS using <a href="https://docs.microsoft.com/en-us/azure/machine-learning/how-to-use-azure-ad-identity" rel="nofollow noreferrer">this documentation</a>. One of the step is to edit the deployment to add identity-feature label at <code>/spec/template/metadata/labels</code> for the deployment (see para starting like <code>Edit the deployment to add ...</code> in <a href="https://docs.microsoft.com/en-us/azure/machine-learning/how-to-use-azure-ad-identity#assign-azure-identity-to-machine-learning-web-service" rel="nofollow noreferrer">this section</a>). </p>
  
  <p>I wish to automate this step using python kubernetes client (<a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">https://github.com/kubernetes-client/python</a>). Browsing the available API, I was wondering that perhaps <code>patch_namespaced_deployment</code> will allow me to edit deployment and add label at <code>/spec/template/metadata/labels</code>. I was looking for some example code using the python client for the same - any help to achieve above will be appreciated.</p>