Run different component of an app in same deployment in GCP Kubernetes engine?

2/6/2019

I have an app with multiple components say x,y,z, I want to run x,y with 3 pods and z with 1 pod. How can I do this in one deployment.yaml file in Kubernetes engine on GCP?

-- Darshan Naik
google-cloud-platform
google-kubernetes-engine
kubernetes
node.js

1 Answer

2/6/2019

I dont think deployment can help you in this situation but StatefulSet might help here with some changes in your application as well.

As StatefulSet always create pods with some naming conventions and it stick to it even if pods are recreated. Pods are generally named as -INDEX like mypod-1, mypod-2 etc.

So make use of it, allocate first 3 pods to your two component by disabling third component. Use pod name environment variable and if pod name is not with index 4, disable your third component(this logic has to be in you application) and for pod name with index 4 , disable first two components.

You can use pod name as env variable using below configuration,

- name: Pod_Name
  valueFrom:
    fieldRef:
      fieldPath: metadata.name 
-- Rajesh Deshpande
Source: StackOverflow