Score:0

How to minimize the number of deployments in kubernetes, how to tie pods to configmaps?

je flag

Want to start by saying I'm pretty new to Kubernetes and I'm finding it hard to formulate a proper question.

The implementation I'm using of k8s is microk8s.

I have this application that analyzes a feed from a camera. The url of the camera feed is configurable.

At the moment I have 10 cameras. My current solution is to have 10 different deployments and 10 different configmaps looking like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: camera-1-10
spec:
  replicas: 1
  selector:
    matchLabels:
      app: camera-1-10
  strategy: {}
  template:
    metadata:
      labels:
        app: camera-1-10
    spec:
      volumes:
        - name: camera-config
          configMap:
            name: camera1.json
      containers:
      - image: xxxxx.azurecr.io/camera-application:0.0.14
        name: myrepo
        ports:
          - containerPort: 3000
        volumeMounts:
          - name: camera-config
            mountPath: "/config/camera.json"
            subPath: "data"
      imagePullSecrets:
        - name: acrsecret

What I don't like about this solution is that I have 10 deployment-yamls and if I want to update the version number of the application I have to change in 10 different files. It also feels like the work of adding a new camera is more than I would like.

Is there an easier way of solving this? Can I have 1 deployment which describes what container to use. Then 10 pods just referencing different configmaps? Is there a way of adding a new camera by just using configs? To define the number of different camera-pods by configuring something in k8s?

Score:0
gi flag

You could make a Deployment with a replica count of for example 10, which would eliminate your deployment problem of a new version.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 10

You would now have the new problem how to assign each pod a unique configuration. You could still map all different configuration to you're deployment, but your code now has somehow to determine which configuration will be for which pod. You need some kind of logic which will give a pod a configuration which isn't already used by a other pod.

As an idea to solve this, by creating a 2. App.

  1. The first App (camera-manager) does contain all configurations. Maybe an WebApp, so you can easy create, update your configurations.
  2. Your deployments of the camera-application apps will ask the first App (camera-manager) for a configuration which isn't use.

As a further improvement, your First App (camera-manager) will even scale the "camera-application" by the k8s API with each new config or delete configuration.

Or create a script which will do the deployment of your apps. (Map configuration and update version).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.