I'm new to docker/k8s world... I was asked if I could deploy a container using args to modify the behavior (typically if the app is working in "master" or "slave" version), which I did. Maybe not the optimal solution but it works:
This is a simple test to verify. I made a custom image with a script inside: role.sh:
#!/bin/sh
ROLE=$1
echo "You are running "$ROLE" version of your app"
Dockerfile:
FROM centos:7.4.1708
COPY ./role.sh /usr/local/bin
RUN chmod a+x /usr/local/bin/role.sh
ENV ROLE=""
ARG ROLE
ENTRYPOINT ["role.sh"]
CMD ["${ROLE}"]
If I start this container with docker using the following command:
docker run -dit --name test docker.local:5000/test master
I end up with the following log, which is exactly what I am looking for:
You are running master version of your app
Now I want to have the same behavior on k8s, using a yaml file. I tried several ways but none worked.
YAML file:
apiVersion: v1
kind: Pod
metadata:
name: master-pod
labels:
app: test-master
spec:
containers:
- name: test-master-container
image: docker.local:5000/test
command: ["role.sh"]
args: ["master"]
I saw so many different ways to do this and I must say that I still don't get the difference between ARG and ENV.
I also tried with
- name: test-master-container
image: docker.local:5000/test
env:
- name: ROLE
value: master
and
- name: test-master-container
image: docker.local:5000/test
args:
- master
but none of these worked, my pods are always in CrashLoopBackOff state.. Thanks in advance for your help!