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 asdockerd
from 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-sample
in a terminal as follows:cd docs.rancherdesktop.io/assets/express-sample
-
Run
skaffold init
.Per the Skaffold docs,
skaffold init
walks 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
Dockerfile
andpackage.json
in our example. This will generate the initial configuration file that you can modify as needed. When prompted, selectyes
to write your config toskaffold.yaml
. -
In your editor, review your
app.js
andmanifests.yaml
files. Note that inmanifests.yaml
, you will have a deployment config as well as a service config. It is only necessary to have 1replica
for testing purposes. -
Back in your terminal, you'll notice that you will have two options:
skaffold run
that lets you build and deploy, andskaffold dev
that allows you to enter development mode with auto-redeploy. We will useskaffold dev
in this example.You will need to have push access to the image repository. You can either use your docker login, set up a local registry, or build locally without pushing to an image registry:
- Docker Hub
- Local Registry
- Local Build
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
You can build locally without pushing to the image registry by setting your workloads imagePullPolicy
to IfNotPresent
in your manifests.yaml
file. You will also need to update your skaffold.yaml
with the following variables in order to implement this change as noted below:
Example YAML
apiVersion: skaffold/v2beta29
kind: Config
metadata:
name: skaffold
build:
local:
push: false
useDockerCLI: true
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-sample
screen.