<p>In Kubernetes, it is possible to make a service running in cluster externally accessible by running <code>kubectl expose deployment</code>.  Why deployment as opposed to service is beyond my simpleton's comprehension.  That aside, I would like to also be able to undo this operation afterwards.  Think of a scenario, where I need to get access to the service that normally is only accessible inside the cluster for debugging purposes and then to restore original situation.</p>

<p>Is there any way of doing this short of deleting the deployment and creating it afresh?</p>

<hr>

<p>PS. Actually deleting service and deployment doesn't help. Re-creating service and deployment with the same name will result in service being exposed.</p>

<p>Assuming you have a deployment called hello-world, and do a kubectl expose as follows:</p>

<p><code>kubectl expose deployment hello-world --type=ClusterIP --name=my-service</code></p>

<p>this will create a service called my-service, which makes your deployment accessible for debugging, as you described.</p>

<p>To display information about the Service:</p>

<p><code>kubectl get services my-service</code></p>

<p>To delete this service when you are done debugging:</p>

<p><code>kubectl delete service my-service</code></p>

<p>Now your deployment is un-exposed.</p>
