Kube Cloud | Automate Kube Deploy

Kube Cloud | Automate Kube Deploy

Kubernetes Application Hosted in the Cloud

full course
  1. Kubernetes Application Hosted in the Cloud
  2. Cloud Kube | Create Github Repo
  3. Cloud Kube | Simple REST Endpoint and Test
  4. Cloud Kube | Build Pipeline Initialization
  5. Cloud Kube | Docker Build and Registry
  6. Cloud Kube | Helm Initialization and Chart Publishing
  7. Cloud Kube | Setup Cloud Hosting
  8. Kube Cloud | Automate Kube Deploy

Lets improve our CD pipeline by automating deployment.

Update Build Pipeline

I only want main to deploy on successful build. So add these lines to the end of the main.yaml github action workflow

      - name: Deploy
        uses: WyriHaximus/github-action-helm3@v2
        with:
          exec: |
            helm repo add bullyrooks https://bullyrooks.github.io/helm-charts/
            helm repo update
            helm upgrade cloud-application bullyrooks/cloud-application --install --atomic
          kubeconfig: '${{ secrets.KUBECONFIG }}'

This is going to execute the same things we just did manually

  • Add the chart repository
  • Update it
  • Upgrade the cloud instance if it exists, otherwise install (--install) and rollback if it fails (--atomic).

You can see that we need to add a secret so lets do that.

Add the Okteto Kube Config

Navigate to the github repository settings/secrets section

Create a new secret called KUBECONFIG paste the entire contents of the okteto-kube.config file in as the value.

Redeploy and Verify

Push your changes up to main

$ git add .

$ git commit -m "automated deployment"
Writing objects: 100% (5/5), 623 bytes | 623.00 KiB/s, done.
Total 5 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com-bullyrook:bullyrooks/cloud_application.git
   9f9185a..aa3d54b  main -> main

$ git push

Now navigate back to your github actions tab. Confirm that the build kicked off.

Under Publish Helm Chart you should see a new version got created

Successfully packaged chart and saved it to: /tmp/tmp.bkbDop/cloud-application-1.0.16.tgz

Under Deploy you should see that it deployed

Release "cloud-application" has been upgraded. Happy Helming!
NAME: cloud-application
LAST DEPLOYED: Wed Jan  5 00:27:43 2022
NAMESPACE: ***
STATUS: deployed
REVISION: 3
NOTES:
1. Get the application URL by running these commands:
  export NODE_PORT=$(kubectl get --namespace *** -o jsonpath="{.spec.ports[0].nodePort}" services cloud-application)
  export NODE_IP=$(kubectl get nodes --namespace *** -o jsonpath="{.items[0].status.addresses[0].address}")
  echo http://$NODE_IP:$NODE_PORT

Now navigate to okteto and expand the deployment, check the yaml to see if the new version was deployed

And double check in postman

There you go! Now any changes made into a feature branch will build and test. When you have confidence it can release you can merge to main and it will get deployed into your cloud hosted environment.

This make updating your application much easier. However, it can be made much easier with tools like skaffold that hook into your IDE and build and push changes automatically after code changes.

0 comments on “Kube Cloud | Automate Kube DeployAdd yours →

Leave a Reply

Your email address will not be published. Required fields are marked *