Search code examples
kubernetesdeploymentcontainersopenshift

Containers with the same image version but with different configs


Is there a way to have an application with 2 containers with the same image version but with different name and resources on OpenShift?

For example: In the same namespace, given a micro service with set with replicas: 6, with the metada name "app-banking", I would like to have 3 pods with envs ABC and name "app-banking-aaa-<pod_hash>", and other 3 pods with name "app-banking-bbb<pod_hash> and envs VXZ.

Didn't find anything like this on the internet.

Since we have two Kafka Bootstraps-servers, we have some consumers services that we are trying to implement "cross-broker" solution, in the same namespace.

So 3 pods will have envs to connect to Bootstrap-Server1 and other 3 pods to Bootstrap-Server2.

Appreciate the help.


Solution

  • When you deploy an application on OpenShift/Kubernetes, you need to create Deployments*1 resource on the cluster.

    Deployments is one of the resources in Kubernetes and helps you to manage your application (Pod). Deployments have fields to specify a container image url and environment variables. So that it is easy to deploy applications using same container images but using different environment variables. Here is an example.

    Application app-baking-aaa-<pod_hash>

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: app-banking-aaa
      labels:
        app: app-banking-aaa
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: app-banking-aaa
      template:
        metadata:
          labels:
            app: app-banking-aaa
        spec:
          containers:
          - name: app-banking
            image: https://path-to-your-registry/your-app:tag1
            env:
            - name: ABC
              value: abc
    
    

    Application app-banking-bbb-<pod_hash>

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: app-banking-bbb
      labels:
        app: app-banking-bbb
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: app-banking-bbb
      template:
        metadata:
          labels:
            app: app-banking-bbb
        spec:
          containers:
          - name: app-banking
            image: https://path-to-your-registry/your-app:tag1
            env:
            - name: VXZ
              value: vxz
    
    

    You many need to add more fields on the deployment however, the above deployments could help you to understand what you need to do.

    I think you also need to search ConfigMap and Secrets resource for defining environment variables in Deployments.

    *1: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/