Even though the question has already been answered, I wanted to provide an example using Go templating:
kubectl get deployment $GKE_DEPLOYMENT_NAME \
--namespace=$GKE_DEPLOYMENT_NAMESPACE \
--output=go-template \
--template='{{range .spec.template.spec.containers}}{{.image}}{{"\n"}}{{end}}'
#=>
us.gcr.io/. . ./. . .:xxxxxxx
Note: if your deployment
contains more than one container, this command will list all Docker Images; since containers
is either a JSON array or YAML sequence, there is no guaranteed order. I.e. selecting by element index isn't guaranteed to return the intended Docker Image Repo. and Tag.
Note: if you are using this command in order to determine what git
commit
is currently deployed, through Docker Tags or Docker Labels, you will need to introduce string manipulation.
You may want to label
your deployment
instead:
kubectl label \
--overwrite=true \
deployment $GKE_DEPLOYMENT_NAME \
commit=$(git rev-parse --short HEAD) \
--namespace=$GKE_DEPLOYMENT_NAMESPACE \
--record=true
#=>
deployment.apps/$GKE_DEPLOYMENT_NAME labeled
and access this label
, regardless of multiple Docker Images and without string manipulation, using:
kubectl get deployment $GKE_DEPLOYMENT_NAME \
--namespace=$GKE_DEPLOYMENT_NAMESPACE \
--output=go-template \
--template='{{index .metadata.labels "commit"}}{{"\n"}}'
#=>
xxxxxxx