kubernetes create multiple pods/deployments of the same image with different command
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Kubernetes is a powerful container orchestration platform that allows the automated deployment, scaling, and management of containerized applications. One of its powerful features is the ability to create multiple pods or deployments from the same Docker image but execute different commands or configurations for each.
Understanding Pods and Deployments
Pods: Pods are the smallest and most basic deployable objects in Kubernetes. A Pod represents a single instance of a running process in your cluster. Pods contain one or more containers, such as Docker containers. When a Pod runs multiple containers, they are managed as a single entity and share the Pod's resources, including networking and storage.
Deployments: Deployments provide declarative updates for Pods and ReplicaSets. You define a desired state and the Deployment Controller changes the actual state to the desired state at a controlled rate. Deployments can scale the number of replicas, roll out changes, and rollback to previous versions if necessary.
Creating Multiple Deployments with Different Commands
To create deployments using the same image but with different startup commands, you need to define multiple deployment YAML files, each specifying a different command in the container spec.
Example Scenario
Assume you have a Docker image `example-image:1.0` containing an application that can run with different modes: `mode-one` and `mode-two`. These modes are set by passing different commands or arguments to the container at runtime.
Deployment YAML Files
Here are two deployment YAML files:
- Mode-One Deployment:
- name: example-container
- containerPort: 80
- name: example-container
- containerPort: 80
- Environment-Specific Configurations: In more complex scenarios, leverage ConfigMaps and Secrets to inject environment-specific configurations.
- Helm Charts: Consider using Helm to template out multiple environments and parameters. This can simplify the management of configurations for deploying multiple instances of Pods with different configurations.
- Monitoring and Logging: Ensure that your deployments include relevant monitoring and logging setups, as different configurations might warrant different observability approaches.

