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.
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.
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.
Any indication then on how to temporarily STOP / RESUME a kubernetes service in Google cloud, while preserving it's IP?
Thanks
Kubernetes itself does not have mechanism to stop a service.
When you create a Service
type of LoadBalancer in GKE
, it automatically creates a forwarding rule for external access. You can disable that rule (not delete!) to stop external traffic accessing your Service.
To disable the forwarding rule:
$ kubectl get svc
GCP Dashboard -> Kubernetes Engine -> Services & Ingress
GCP Dashboard -> VPC Network -> External IP addresses
GCP Dashboard -> VPC Network -> Firewall
From a GKE
perspective you can create a service type of LoadBalancer
with a static IP address that will be bound and available to your project as long as it's not released. Even if you delete a Service
in your GKE
cluster it will still be available to bound to your recreated Service
.
You can do it by either:
Service
creationGCP Dashboard -> VPC Network -> External IP addresses -> Reserve Static Address
Service
type of LoadBalancer with previously created IP address. Example below: 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
Please take a specific look on part:
loadBalancerIP: PASTE_HERE_IP_ADDRESS
as this line is required to have previously created static IP address.
Deleting this Service will:
Service
in GKE
Service
and IP address in GCP Dashboard
Service
before reserving static IP addressAssuming that you have already created a Service
type of LoadBalancer you can:
GCP Dashboard -> VPC Network -> External IP addresses
Ephemeral
to Static
. This will ensure that this IP will not be released when Service got deleted. loadBalancerIP: PASTE_HERE_IP_ADDRESS
If you changed your IP address type from Ephemeral
to Static
, deleting your Service
will not release your Static
IP address.
Please take a look on additional documentation:
Please let me know if you have any questions in that.