GKEPhalanxClusterService#
- class phalanx.services.cluster.GKEPhalanxClusterService(kubernetes_storage)#
Bases:
objectKubernetes operations on a GKE Phalanx cluster.
These operations are not in the EnviromentService because:
They do not necessarily correspond 1-1 to a Phalanx enviroment.
They are often part of tasks that involve multiple clusters, so passing an explicit context is less error prone, and allows the operations to be automated without having to manually change the kubectl current context.
Some of the operations are specific to Google Cloud GKE clusters, like waiting for an associated cloud load balancer to be destroyed when converting a Service from LoadBalancer to ClusterIP.
For example, when recovering a GCP cluster from backups while the old cluster still exists, you will need to work with two clusters, both of which are associated with the same environment.
- Parameters:
kubernetes_storage (
KubernetesStorage) – Interface to direct Kubernetes object manipulation.
Methods Summary
Get all Services of type LoadBalancer for all Phalanx apps.
Print the version of the kubectl client and kubernetes server.
Release all IPs on LoadBalancer Services for all Phalanx apps.
Restore all IPs on LoadBalancer Services for all Phalanx apps.
Resume all CronJobs in all Phalanx apps.
Set the persistentVolumeReclaimPolicy to Retain for all PVs.
Scale down all Phalanx workloads except ArgoCD and crons.
Scale down (almost) all Phalanx workloads.
Scale up all Phalanx workloads and resume all crons.
Scale up (almost) all Phalanx workloads to their previous counts.
Suspend all CronJobs in all Phalanx apps.
Methods Documentation
- get_phalanx_load_balancer_services()#
Get all Services of type LoadBalancer for all Phalanx apps.
We say a Service is in a Phalanx app if it has an ArgoCD label.
- kube_version()#
Print the version of the kubectl client and kubernetes server.
Useful for checking that kubectl can connect to a cluster using a given context.
- Return type:
- release_service_ips()#
Release all IPs on LoadBalancer Services for all Phalanx apps.
This will clear any spec.loadBalancerIPs, then change the Service type from LoadBalancer to ClusterIP, then back to LoadBalancer.
This can be used when recovering a Phalanx cluster to another GKE cluster while the old cluster is still running.
- Returns:
A list of Services with refreshed IPs.
- Return type:
- Raises:
InvalidLoadBalancerServiceStateError – If the service resource does not have exactly one of spec.loadBalancerIP or an annotation for the previous loadBalancerIP set.
ServiceMissingTrafficPolicyError – If the service resource does not have an externalTrafficPolicy.
- restore_service_ips()#
Restore all IPs on LoadBalancer Services for all Phalanx apps.
This is only intended to be run after a release operation because it depends on an annotation set during that operation.
- Raises:
InvalidLoadBalancerServiceStateError – If the service resource does not have exactly one of spec.loadBalancerIP or an annotation for the previous loadBalancerIP set.
- Return type:
- scale_down_workloads()#
Scale down (almost) all Phalanx workloads.
During cluster rebuilds when there is an old and a new cluster, certain workloads can’t be running in both clusters at the same time, or else state external to the cluster could be corrupted.
We’ll leave ArgoCD running so the scaled-down cluster can still be inspected.
- Raises:
InvalidScaleStateError – If the workload resource has a previous replica count annotation, but its current replica count is not zero.
- Return type:
- scale_up_workloads()#
Scale up (almost) all Phalanx workloads to their previous counts.
This is only intended to be run after a scale down operation.
- Raises:
InvalidScaleStateError – If the workload resource has a previous replica count annotation, but its current replica count is not zero.
- Return type: