gerasalus
gerasalus

Reputation: 7707

How do you manage kubernetes deployment yaml file with continuous delivery?

Let's say I have a simple deployment kubernetes config:

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: backend
spec:
  replicas: 1
  template:
    metadata:
      name: backend
    spec:
      containers:
      - name: backend
        image: backend:1.0.0
        resources:
          limits:
            memory: "500Mi"
            cpu: "100m"
        imagePullPolicy: Always

And I want to have continuous deployment.

Upvotes: 2

Views: 2101

Answers (2)

rln
rln

Reputation: 121

I'm assuming you have the yaml files in the same repo as the code you're building.

We used a label (ie :snapshot) in the YAML file. This was however only used when initially created, or when you used "kubectl apply" to apply other changes to the file. When CI was done building, it ran essentially:

docker build -t <image>:<id> -f Dockerfile .
docker push <image>:<id>
docker tag <image>:<id> <image>:<snapshot>
docker tag <image>:snapshot
docker push <image>:snapshot
kubectl set image deployment <depl> <foo>=<image>:<id>

We never had issues with this, as we seldom updated the YAML files; however, you could never be sure there wasn't an old version of :snapshot cached somewhere.

If you want to always do "kubectl apply" in CI, you'll need to inject the label externally somehow (e.g. via sed, or through some kind of templating):

docker build -t <image>:${CI_BUILD_LABEL} -f Dockerfile .
docker push <image>:${CI_BUILD_LABEL}
cat template/deployment.yaml | sed s/MYPOD_VERSION/${CI_BUILD_LABEL} | kubectl apply -f -

Upvotes: 0

Oswin Noetzelmann
Oswin Noetzelmann

Reputation: 9555

Helm charts become an increasingly popular way of managing kubernetes deployments. In short it allows you to generate deployments with only defining the variables that you need with a simple configuration and it has a built in upgrade mechanism as well. In other words it provides meta-deployments.

Refer to the following docs.

Upvotes: 3

Related Questions