<p>I deployed a (LoadBalancer) service for a pod on my minikube cluster, then exposed it via <code>minikube service [my_service]</code> command. Now I tried to &quot;turn off the exposure&quot; but couldn't find any way to do this, except deleting it what I would like to avoid. Is it possible to just turn off the exposure, not deleting (and redeploying) the existing already exposed service?</p>

pullback
<h3>Background</h3>
<p>In Kubernetes documentation regarding <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">ServiceTypes</a>, you can find information that if you want to expose your cluster outside you have to use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">NodePort</a> or <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">LoadBalancer</a>.</p>
<p>If you want to keep your service/application in cluster, you should use <code>ClusterIP</code>:</p>
<blockquote>
<p>Exposes the Service on a <code>cluster-internal IP</code>. <strong>Choosing this value makes the Service only reachable from within the cluster</strong>. This is the default ServiceType.</p>
</blockquote>
<p>Depends on your version, you can edit it or use workaround. For example in K8s <strong>1.16</strong> you won't be able as some errors might occurs.</p>
<pre><code>$ kubectl get svc
NAME         TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)        AGE
kubernetes   ClusterIP      10.8.0.1      &lt;none&gt;          443/TCP        3d20h
my-nginx     LoadBalancer   10.8.14.224   34.121.77.108   80:32039/TCP   3m16s
$ kubectl patch service my-nginx -p '{&quot;spec&quot;:{&quot;type&quot;:&quot;ClusterIP&quot;}}'
The Service &quot;my-nginx&quot; is invalid: spec.ports[0].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'

</code></pre>
<h3>Solutions</h3>
<p>However as you are using <code>Minikube</code> so I guess you are using newer version (1.20), so you can change it using:</p>
<ol>
<li><strong>kubectl edit</strong></li>
</ol>
<p><code>kubectl edit svc &lt;yourSvcName&gt;</code> and change type to <code>ClusterIP</code>.
It will open <code>Vi</code> editor, where you can change <code>spec.type</code> to <code>ClusterIP</code> or just remove it as default type for Kubernetes service is <code>ClusterIP</code> so if it won't be specified, Kubernetes will automatically use <code>ClusterIP</code>.</p>
<pre><code>$ kubectl get svc
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1        &lt;none&gt;        443/TCP        25s
my-nginx     LoadBalancer   10.107.129.201   &lt;pending&gt;     80:30173/TCP   8s
minikube-new:~$ kubectl edit svc my-nginx
service/my-nginx edited
sekreta@minikube-new:~$ kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP   46s
my-nginx     ClusterIP   10.107.129.201   &lt;none&gt;        80/TCP    29s
</code></pre>
<ol start="2">
<li><strong>kubectl patch</strong></li>
</ol>
<p><code>$ kubectl patch service &lt;yourServiceName&gt; -p '{&quot;spec&quot;:{&quot;type&quot;:&quot;ClusterIP&quot;}}'</code></p>
<pre><code>$ kubectl get svc
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1        &lt;none&gt;        443/TCP        10m
my-nginx     LoadBalancer   10.107.129.201   &lt;pending&gt;     80:30456/TCP   2m
minikube-new:~$ kubectl patch service my-nginx -p '{&quot;spec&quot;:{&quot;type&quot;:&quot;ClusterIP&quot;}}'
service/my-nginx patched
minikube-new:~$ kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP   10m
my-nginx     ClusterIP   10.107.129.201   &lt;none&gt;        80/TCP    3m
</code></pre>
<ol start="3">
<li><strong>kubectl apply</strong></li>
</ol>
<p>You can edit your Yaml and remove <code>spec.type</code> or have 2 Yamls with <code>ClusterIP</code> and <code>LoadBalancer</code> and switch them depends on your needs.</p>
<pre><code>$ kubectl apply -f svc.yaml 
service/my-nginx configured
minikube-new:~$ kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP   22m
my-nginx     ClusterIP   10.111.237.133   &lt;none&gt;        80/TCP    16s
</code></pre>
<ol start="4">
<li>Use some 3rd party software to make changes in your cluster like <a href="https://helm.sh/" rel="nofollow noreferrer">Helm</a> and using templates.</li>
</ol>
