I'm using Kubernetes+Helm - and wanting to ask if it possible to get the Docker version as specified in the spec containers. So forexample, I have the deployment below:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: test
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: myrepo.com/animage:0.0.3
imagePullPolicy: Always
command: ["/bin/sh","-c"]
args: [“work”]
envFrom:
- configMapRef:
name: test
I then have another deployment where I would like to get that Docker version number 0.0.3 and set it as an env var.
Any ideas appreciated.
Thanks.
Short answer: No. At least not directly. Although there are two workarounds I can see that you might find viable.
First, apart of providint image with your version tag, set a label/annotation on the pod indicating it's version and use Downward API to pass that data down to your container
https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/
Second, if you actually own the process to build that image, you can easily bake the version in during docker build with something like :
Dockerfile:
FROM ubuntu
ARG VERSION=undefined
ENV VERSION=$VERSION
with build command like
docker build --build-arg VERSION=0.0.3 -t myrepo.com/animage:0.0.3 .
which will give you an image with a baked in env var with your version value