How to pass the build versions dynamically in kubectl command


#1

Hi,

I am pushing the docker images to ECR with version number which is stored in S3 and i am not able to use those version number in kubectl command dynamically

eg:

put: k8s
params:
kubectl: set image deployment/nginx0-deployment nginx=1.amazonaws.com/test
tag: version/number
wait_until_ready: 300
tag: version/number : this value not taking in kubectl argument dynamically


#2

Here’s how I’ve done it with kubernetes-resource:

resource_types:

- name: kubernetes
  type: docker-image
  source:
    repository: zlabjp/kubernetes-resource
    tag: "1.8"

resources:

- name: git-repo
  type: git
  source:
    uri: git@github.com:org/repo.git
    branch: master
    private_key: |
      ((key-ssh-github))

- name: k8s
  type: kubernetes
  source:
    server: https://server
    namespace: default
    token: ((token)
    certificate_authority: |
     ((ca-cert))

jobs:

- name: build-push-deploy

  plan:

  - put: k8s
    params:
      kubectl: |
        patch deployment deploymentname -p '{"spec":{"template":{"spec":{"containers":[{"name":"containername","image":"my-container-image:'$(cat git-repo/.git/ref)'"}]}}}}'

#3

Hi chrishiestand,

  • put: k8s
    params:
    kubectl: set image deployment/nginx0-deployment nginx=".dkr.ecr.ap-south-1.amazonaws.com/test:$(cat version/number)"

with this command i am able to update the deployment but i have tried to pass the variable in yam file which is in git repo but it not updating

nginx.yml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx0-deployment
labels:
app: nginx0-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: nginx0
spec:
containers:
- name: nginx
image: .dkr.ecr.ap-south-1.amazonaws.com/test:${version/number}
#imagePullPolicy: Always
#image: nginx:latest
ports:
- containerPort: 80


#4

yaml does not support variables. Look at how this is done in the example above:

$(cat git-repo/.git/ref)