Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I un-expose (undo expose) service?

In Kubernetes, it is possible to make a service running in cluster externally accessible by running kubectl expose deployment. 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.

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


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

like image 383
wvxvw Avatar asked Feb 06 '18 09:02

wvxvw


People also ask

How do you expose a service?

From the Service type drop-down list, select Cluster IP. Click Expose. When your Service is ready, the Service details page opens, and you can see details about your Service. Under Cluster IP, make a note of the IP address that Kubernetes assigned to your Service.

What does kubectl expose command do?

kubectl expose − This is used to expose the Kubernetes objects such as pod, replication controller, and service as a new Kubernetes service. This has the capability to expose it via a running container or from a yaml file.

How do I access Clusterber services in Kubernetes from outside?

To reach the ClusterIp from an external computer, you can open a Kubernetes proxy between the external computer and the cluster. You can use kubectl to create such a proxy. When the proxy is up, you're directly connected to the cluster, and you can use the internal IP (ClusterIp) for that Service .


1 Answers

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

kubectl expose deployment hello-world --type=ClusterIP --name=my-service

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

To display information about the Service:

kubectl get services my-service

To delete this service when you are done debugging:

kubectl delete service my-service

Now your deployment is un-exposed.

like image 170
Lindsay Landry Avatar answered Sep 21 '22 13:09

Lindsay Landry