<p>I'm trying to run an automation job in Python that restarts a deployment in Kubernetes cluster. I cannon install <code>kubectl</code> on the box due to limited permissions. Does anyone have a suggestion or solution for this?</p>
<p>Thank you.</p>

<p>For configuration follow - <a href="https://github.com/kubernetes-client/python/blob/master/examples/remote_cluster.py" rel="noreferrer">https://github.com/kubernetes-client/python/blob/master/examples/remote_cluster.py</a></p>
<pre><code># This is equivalent to `kubectl rollout restart deployment/dashboard-kubernetes-dashboard -n default`


from kubernetes import client, config
from kubernetes.client.rest import ApiException
import datetime

def restart_deployment(v1_apps, deployment, namespace):
    now = datetime.datetime.utcnow()
    now = str(now.isoformat(&quot;T&quot;) + &quot;Z&quot;)
    body = {
        'spec': {
            'template':{
                'metadata': {
                    'annotations': {
                        'kubectl.kubernetes.io/restartedAt': now
                    }
                }
            }
        }
    }
    try:
        v1_apps.patch_namespaced_deployment(deployment, namespace, body, pretty='true')
    except ApiException as e:
        print(&quot;Exception when calling AppsV1Api-&gt;read_namespaced_deployment_status: %s\n&quot; % e)


def main():
    config.load_kube_config(context=&quot;minikube&quot;)
    # Enter name of deployment and &quot;namespace&quot;
    deployment = &quot;dashboard-kubernetes-dashboard&quot;
    namespace = &quot;default&quot;
    v1_apps = client.AppsV1Api()
    restart_deployment(v1_apps, deployment, namespace)


if __name__ == '__main__':
    main()
</code></pre>
