<p>I have a service named Foo that is currently running. It directs traffic it receives to a running Pod as well. Since the service is of type LoadBalancer and runs in Google Cloud - it has it's own external IP.</p>

<p>I'm currently doing maintenance and testing on various services and would like to temporarily STOP service Foo from working, then RESUMING it again. That is, anyone that hits the IP for service Foo would get a 404, but then later on I resume it - they would start getting answers back.</p>

<p>The reason why I don't just flat out delete the service then create a new one is because I wish to maintain the original IP address for the Foo service. I have tests that directly reference that IP and do not wish to have to continuously change them. i also have a few clients in production relying on that IP so I can't risk losing it. </p>

<p>Any indication then on how to temporarily STOP / RESUME a kubernetes service in Google cloud, while preserving it's IP? </p>

<p>Thanks</p>

<p><strong>Kubernetes itself does not have mechanism to stop a service.</strong> </p>

<hr>

<p>When you create a <code>Service</code> type of LoadBalancer in <code>GKE</code>, it automatically creates a forwarding rule for external access. You can disable that rule (not delete!) to stop <strong>external</strong> traffic accessing your <code>Service.</code></p>

<p>To disable the forwarding rule:</p>

<ul>
<li>Check the associated IP address with a LoadBalancer by either: 

<ul>
<li>issuing: <code>$ kubectl get svc</code></li>
<li>going to: <code>GCP Dashboard -&gt; Kubernetes Engine -&gt; Services &amp; Ingress</code></li>
</ul></li>
<li>Go to <code>GCP Dashboard -&gt; VPC Network -&gt; External IP addresses</code></li>
<li>Find your LB's IP and <strong>copy name of the forwarding rule associated with it</strong></li>
<li>Go to <code>GCP Dashboard -&gt; VPC Network -&gt; Firewall</code></li>
<li>Search for mentioned forwarding rule </li>
<li>Edit it </li>
<li>On the bottom of edit site you should have an option to disable it like picture below: </li>
</ul>

<p><a href="https://i.stack.imgur.com/D8Fkt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D8Fkt.png" alt="GCP1"></a></p>

<hr>

<p>From a <code>GKE</code> perspective you can create a service type of <code>LoadBalancer</code> with a <strong>static IP address</strong> that will be bound and available to your project as long as it's not released. Even if you delete a <code>Service</code> in your <code>GKE</code> cluster it will still be available to bound to your recreated <code>Service</code>. </p>

<p>You can do it by either: </p>

<h2>Reserving static IP address before <code>Service</code> creation</h2>

<ul>
<li>Go to <code>GCP Dashboard -&gt; VPC Network -&gt; External IP addresses -&gt; Reserve Static Address</code> </li>
<li>Create a static IP </li>
<li>Note the IP address created </li>
<li>Create a <code>Service</code> type of LoadBalancer with previously created IP address. Example below: </li>
</ul>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: hello-service-lb
spec:
  selector:
    app: hello
  ports:
    - name: hello-port
      port: 80
      targetPort: 50001
      nodePort: 30051
  type: LoadBalancer
  loadBalancerIP: PASTE_HERE_IP_ADDRESS
</code></pre>

<p>Please take a specific look on part: </p>

<pre class="lang-yaml prettyprint-override"><code>  loadBalancerIP: PASTE_HERE_IP_ADDRESS
</code></pre>

<p><strong>as this line is required to have previously created static IP address.</strong> </p>

<p>Deleting this Service will: </p>

<ul>
<li>Delete a <code>Service</code> in <code>GKE</code></li>
<li>Delete the association between <code>Service</code> and IP address in <code>GCP Dashboard</code></li>
<li>It will not delete the reserved static IP address</li>
</ul>

<h2>Creating a <code>Service</code> before reserving static IP address</h2>

<p>Assuming that you have already created a <code>Service</code> type of LoadBalancer you can:</p>

<ul>
<li>Go to <code>GCP Dashboard -&gt; VPC Network -&gt; External IP addresses</code></li>
<li>Found the IP address associated with your LoadBalancer</li>
<li>Change type of this IP address from: <code>Ephemeral</code> to <code>Static</code>. This will ensure that this IP will not be released when Service got deleted.</li>
<li><strong>You will need to edit your Service definition when recreating it to include</strong>: </li>
</ul>

<pre class="lang-yaml prettyprint-override"><code>  loadBalancerIP: PASTE_HERE_IP_ADDRESS
</code></pre>

<p>If you changed your IP address type from <code>Ephemeral</code> to <code>Static</code>, deleting your <code>Service</code> will not release your <code>Static</code> IP address. </p>

<hr>

<p>Please take a look on additional documentation: </p>

<ul>
<li><a href="https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address" rel="nofollow noreferrer">Cloud.google.com: IP addresses: Reserve static external IP</a></li>
<li><a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/configuring-domain-name-static-ip#step_2a_using_a_service" rel="nofollow noreferrer">Cloud.google.com: Kubernetes Engine: LoadBalancer</a> </li>
</ul>

<p>Please let me know if you have any questions in that. </p>
