logo

How to configure continuous redeployment on K8s ?

To be able to configure redeployment on K8s you need to have a few things configured:

1. Service account on K8s with access to patch the deployment

To create the service account please run the following commands:

kubectl apply -f redeploy/redeploy_sa.yaml redeploy_role.yaml redeploy_rolebinding.yaml

Now we need to get the access token for service account:

kubectl get secrets -n *env*-app redeploy-token -ojson | jq -j '.data.token' | base64 -d

2. Create redepoyment step in drone pipeline

The redeployment step will look similar to this one. Here you can configure both the deployment that you want to update and the tag for the image you want to use.

  - name: "Redeploy on K8s"
    image: komljen/drone-kubectl-helm
    environment:
      KUBERNETES_SERVER:
        from_secret: k8s_server_url
      KUB0ERNETES_CERT:
        from_secret: k8s_server_cert
      KUBERNETES_TOKEN:
        from_secret: k8s_sa_token
      KUBECTL_COMMAND:
        from_secret: k8s_redeploy_cmd
    commands:
      - /run.sh
      - kubectl set image deployment/frontend -n *env*-app frontend=*image_url*:${DRONE_COMMIT_SHA:0:7}

NOTE! THIS TYPE OF REDEPLOYMENT IS MAINLY SUITED FOR FRONTEND APPLICATIONS