Question: I would like to update the version on the label for a kubernetes deployment dynamically based on the version of the underlying docker image. For instance, In this example:

```
...

  labels:
    app: appName
    version: 1.0.0 <----- what I want to get updated
spec:
  containers:
    - image: dockerRepository/imageName:latest
      imagePullPolicy: Always
      name: appName
...

```

I would like to get the version label updated with the version that the docker image has. Not "latest" but the underlying version that latest points to.

Is this possible to be done dynamically or it has to be a manual process?

Answer: 
You can use Helm charts for this purpose. you need to create [custom](https://docs.bitnami.com/tutorials/create-your-first-helm-chart/) chart for your deployment.
In which for label and Image you can use values as :

```
metadata:
  labels:
     version: {{ .Values.tag}}

```

For Image as this:

```
spec:
  containers:
    - image: dockerRepository/imageTag:{{ .Values.tag }}

```

Then in Values.yml, you need to provide values like:

```
tag: <your value>

```

Everytime you need to update the tag with Image version, you can simple update the tag in values.yml and run:

```
helm upgrade --set tag=<your value> <name of your deployment> ./<name of your chart>

```

You can also use `_helpers.tpl` for complex operations.
Usually this is something you'd *tell* Kubernetes, rather than ask it. The Docker "latest" tag is hard to use reliably in Kubernetes: in the context of a Deployment you can easily have different replicas running different "latest" versions, and you have to do some manual steps to cause a Deployment to update itself to a newer "latest".

If you're using a templating tool like [Helm](https://helm.sh/), and each build has a distinct image tag, then it's easy to use the same value (configurable at install time) for the image tag and the label:

```yaml
metadata:
  labels:
    version: {{ quote .Values.tag }}
spec:
  containers:
    - image: dockerRepository/imageTag:{{ .Values.tag }}

```

```sh
helm install ... --set-string tag=20201125 ...

```