Can I Define Environment Variables for a Container using replication controller for each replica?
example:
I have this replication controller :
apiVersion: v1
kind: ReplicationController
metadata:
name: bdirest
labels:
component: bdirest
role: publicapi
spec:
replicas: 2
template:
metadata:
labels:
component: bdirest
role: publicapi
spec:
containers:
- name: bdirest
image: XXX.dkr.ecr.us-west-2.amazonaws.com/rest-latest:XX.XX
imagePullPolicy: Always
env:
- name: MY_RC_NAME
value: bdirest
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: "JAVA_OPTIONS"
value: "-Xmx1G -Xms256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/bdi/dumps/jetty -Dconfig.dir.path=/bdi/conf -Dlog4j.configurationFile=/bdi/logs/rest/log4j2.properties -Djetty.logging.dir=/bdi/logs/rest -DMY_RC_NAME=$(MY_RC_NAME)"
ports:
- containerPort: 8080
name: http
I stated that I want 2 replicas for this component, but I want to define that the first replica will have some kind of unique variable that I could use it inside the component, and the second replica will have its own unique variable.
I rather not use pods variables like "MY_POD_NAME" that I can get from "metadata.name" because I want that variable will always use the same variable and not change every time a pod is killed.
Any idea if it's possible?
As far as I know this feature is not available in kubernetes. Kubernetes manages each PODs as separate entity.
Eg. If POD one dies some reason kubernetes will start another instance of the POD with different host name and IP.
In this use can use cause you need manage this logic with shared persistence storage like database