Skaffold and Rancher Desktop
Skaffold is a command line tool that facilitates continuous development for Kubernetes-native applications. Skaffold handles the workflow for building, pushing, and deploying your application, and it provides building blocks for creating CI/CD pipelines. This enables you to focus on iterating on your application locally while Skaffold continuously deploys to your local or remote Kubernetes cluster. To learn more about Skaffold, refer to the project docs here.
In order to demonstrate the steps to set up Skaffold with Rancher Desktop, a sample nodejs app example is provided within the Rancher Desktop docs repository here.
Important: Skaffold only works with
dockerd(Moby). Therefore, make sure to select your runtime asdockerdfrom the Kubernetes Settings panel in the Rancher Desktop UI.
-
Visit https://skaffold.dev/docs/install/ to install Skaffold.
-
Clone the Rancher Desktop docs repository and navigate to the
express-samplein a terminal as follows:cd docs.rancherdesktop.io/assets/express-sample -
Run
skaffold init.Per the Skaffold docs,
skaffold initwalks through your project directory and looks for any build configuration files such asDockerfile,build.gradle/pom.xml,package.json,requirements.txt, orgo.mod.We will select
Dockerfileandpackage.jsonin our example. This will generate the initial configuration file that you can modify as needed. When prompted, selectyesto write your config toskaffold.yaml. -
In your editor, review your
app.jsandmanifests.yamlfiles. Note that inmanifests.yaml, you will have a deployment config as well as a service config. It is only necessary to have 1replicafor testing purposes. -
Back in your terminal, you'll notice that you will have two options:
skaffold runthat lets you build and deploy, andskaffold devthat allows you to enter development mode with auto-redeploy. We will useskaffold devin this example.As you will need to have push access to the image repository, you can either use your docker login, or you can set up a local registry:
- Docker Hub
- Local Registry
Before running skaffold dev, use your docker login if you have a Docker Hub account. Then, in the files skaffold.yaml and manifests.yaml replace matamagu/express-sample for YOUR_DOCKER_HUB_USERNAME/express-sample as skaffold dev will push the built image to DockerHub.
You can set up a local registry by first running this command:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
Then:
skaffold dev --default-repo=localhost:5000
As you go through your development, Skaffold will detect any changes and will automatically go through the build and deployment process again. You will be able to see any changes reflected in the cluster.
- Point your web browser to
localhost:3000, and you will see theexpress-samplescreen.