Skip to main content

Hot reload images for kubernetes with DevSpace

DevSpace is a great tool built by the folks at loft.sh who also built other awesome projects like vcluster.

DevSpace supercharges the development workflow by updating containers in real-time on the kubernetes environment. This has two benefits:

  1. The image build and deploy time is dramatically reduced for faster build loops for engineers.
  2. The deploy is done directly to the kubernetes cluster so development is as close to the final deploy as possible.

Steps

  1. kubectl access to argonaut environment

    • Initialize Kubeconfig $ art update-kubeconfig --name cluster-name --region <region> [flags]****
    • Make sure the AWS Cli is configured. If not then go ahead & run $ aws configure
    • Install jq $ sudo apt-get install jq
    • Once the configuration is complete, run the following command to assume access role, if required.

    $ eval $(aws sts assume-role --role-arn <ROLE_ARN_FROM_CONSOLE> --role-session-name DEVSPACE-SESSION | jq -r '.Credentials | "export AWS_ACCESS_KEY_ID=\(.AccessKeyId)\nexport AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey)\nexport AWS_SESSION_TOKEN=\(.SessionToken)\n"')

  2. ECR repository authentication

    $ aws ecr get-login-password --region <REGION> | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com

  3. Setup DevSpace in source code repository

  • Run $ devspace init. Select “helm: Use my own Helm chart” option

Initialize devspace

Initialize DevSpace

  • Then Select “Use a chart from another git repository” option

Select deployment configuration source as helm

Select deployment configuration source as helm

  • Enter following details while prompted :
    1. chart repository: https://github.com/argonautdev/charts.git
    2. branch name: v0.5.0
    3. According to the type of service you selected while deploying application in Argonaut environment, enter the path to chart as ./charts/<SERVICE_TYPE> for example, ./charts/stateless

Select helm chart path

Select helm chart path

  • It will prompt for default app image name, enter ECR image URL example. <ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/APPNAME

Container image to be deployed

Container image to be deployed

  • It will ask for Build method. Select “Based on this existing Dockerfile” option
  • Enter the port number on which application listens. example: 3000

Port exposed by application

Port exposed by application

NOTE: DevSpace initialization will create devspace.yaml file. This file can be added to repository & pushed with code. Also the folder .devspace must be ignored in .gitignore file.

  1. Add valid art.yaml file from .art directory to .devspace/chart-repo/<PATH_TO_HELM_CHART>/values.yaml path. This file contains values for helm chart specific to application’s deployment. $ cp -f .art/<ART_FILE.yaml> .devspace/chart-repo/<PATH_TO_HELMCHART>/values.yaml
  2. The configuration is complete. Now to start DevSpace, run $ devspace dev

This will start syncing local file system changes with remote pod changes. The application needs to be started manually in the shell after devspace dev.

You can use https://github.com/remy/nodemon to hot reload code changes for any programming languages

For NodeJS$ nodemon server.js

For GoLang$ nodemon --exec "go run" ./main.go

For Python$ nodemon --exec "python -v" ./app.py