This document describes how to get started using Skaffold as part of Google Cloud Deploy, including the following:
- Configuring Skaffold for use with a Google Cloud Deploy delivery pipeline
- Using Skaffold and Google Cloud Deploy with third-party rendering tools, such as Helm and Kustomize
- Optionally, using Skaffold for local development
- Optionally, using Skaffold for continuous integration and continuous deployment (CI/CD)
Why Skaffold?
Want to know why Google Cloud Deploy uses Skaffold, and why you need to manage a Skaffold configuration? Read on.
I'm experienced with CI/CD, but I don't use Skaffold currently
Skaffold is an open source command-line tool to improve productivity for developers. It orchestrates continuous development, continuous integration (CI), and continuous delivery (CD).
Skaffold provides declarative, portable configuration, using a pluggable architecture, allowing you to use different tools for the render phase.
When a release is created, Google Cloud Deploy calls Skaffold to render your manifests and then to apply those manifests to deploy your application to each target in your progression. Upon deployment, Skaffold health checks monitor the target cluster for successful deployment.
Skaffold for continuous development
You can use Skaffold for continuous development, so that images are built, tested, and deployed to a cluster (or Minikube) as you make changes to your code. Cloud Code for VS Code and Cloud Code for IntelliJ IDE extensions integrate Skaffold into Visual Studio Code and JetBrains IDEs, for continuous development.
Skaffold for continuous delivery
You can also use Skaffold for continuous delivery,
with build, deploy, render, and apply steps. Google Cloud Deploy uses
Skaffold's render and apply
capabilities. To use Google Cloud Deploy, you need at least a valid
skaffold.yaml
configuration file.
Through Skaffold, you can also integrate with third-party manifest-management
tools, such as Helm, and Kustomize.
This lets you use the features of those tools for manifest rendering. kubectl
remains the deployer for these manifests.
I'm new to deploying to Kubernetes
With Skaffold, you can configure a base set of manifests for all your deployments, then use Skaffold's rendering engine, through Google Cloud Deploy, to render, and then deploy, each deployment-specific manifest from one of those base manifests.
You can read more about managing manifests, including examples of how to use Skaffold and Google Cloud Deploy with common manifest-templating tools, such as Helm and Kustomize.
What's required to make Google Cloud Deploy work?
To use a basic Google Cloud Deploy delivery pipeline, the
skaffold.yaml
configuration file
needs at least the following configuration:
The header information that all
skaffold.yaml
configurations need:apiVersion: skaffold/v2beta28 Kind: Config
A
deploy
stanza, with the following properties:deploy: kubectl: manifests: -
Under
manifests
, a list of all Kubernetes raw manifests. If you plan to use a renderer (Helm or Kustomize, for example) to render manifests to be deployed, see Adding Kustomize support to your skaffold.yaml and Adding Helm support to your skaffold.yaml for guidance on the configuring Skaffold to use these tools.
Create a skaffold.yaml
file
Google Cloud Deploy uses Skaffold for rendering and deploying your applications.
At a minimum, you need to provide a skaffold.yaml
file that identifies the
manifests to use. Here's an example:
apiVersion: skaffold/v2beta28
kind: Config
deploy:
kubectl:
manifests:
- MANIFEST
In this configuration, MANIFEST
is the path to the
manifest or manifests to be processed by Skaffold.
Have Google Cloud Deploy generate your skaffold.yaml
Google Cloud Deploy can generate a skaffold.yaml
file for you if you
don't have one, but you have a single Kubernetes manifest. The following command
includes the --from-k8s-manifest
flag, passing the manifest. Google Cloud Deploy
uses the information in the manifest to generate the skaffold.yaml
, which is
then used for the release.
gcloud deploy releases create RELEASE_NAME --delivery-pipeline=PIPELINE_NAME --from-k8s-manifest=MANIFEST --region=REGION
Using this flag with either the --skaffold-file
flag or the --source
flag
generates an error.
Using the generated skaffold.yaml
file
The generated skaffold.yaml
is suitable for onboarding, learning, and
demonstrating Google Cloud Deploy. Going forward, and for production workloads, you might want
a skaffold configuration that differentiates among your targets (using
Skaffold profiles).
When you use the generated skaffold.yaml
file as a starting point to create
your own differentiated Skaffold config, be sure you use the file in the
rendering source archive, not the rendered file. The rendering source is
available to download from the Artifacts tab on the **Release details **
page.
This generated
skaffold.yaml
is included in the render source stored in a Cloud Storage bucket.You can view this file by downloading the
.tar.gz
file and extracting it.The rendered
skaffold.yaml
is available in Target artifacts.Under Target artifacts, click View artifacts.
Using Skaffold for local development
One of Skaffold's strengths is that you can use it for local
development, as well as for CI/CD.
In dev
mode, Skaffold watches your source files, and when it detects a change,
Skaffold rebuilds the images, re-tests, and redeploys the containers to a
minikube cluster (for example) on your local machine.
When using Skaffold in this way, you can use the same commands locally as for remote deployment.
If you use Skaffold for local development, you can define separate Skaffold profiles for your targets, and a default deploy stanza for local development.
When you stop dev
mode, Skaffold cleans up deployed artifacts from the cluster.
Using Skaffold for CI/CD
In addition to Skaffold's continuous local build and deploy for your development loop, Google Cloud Deploy uses Skaffold's CI/CD features to render and apply your manifests and deploy your application to your defined targets, given container images built using a CI tool like Cloud Build and an image registry like Artifact Registry.
Render, deploy, and apply
Skaffold separates the manifest rendering process from deployment.
Google Cloud Deploy calls skaffold render
,
to render the manifests, and skaffold apply
to apply them to the target.
This separation between render and apply allows you to capture the full declarative state of your application in configuration, so that it can be applied in a safely repeatable way, for example for rollbacks. This also makes approvals easier. Because manifests are rendered for all targets before the first rollout, you can see the rendered YAML that will be applied to each target.
Google Cloud Deploy doesn't support using other deployers to deploy your application. You can, however, use tools like Helm or Kustomize for rendering.
To learn more about how Google Cloud Deploy deploys using kubectl
as the
deployer, see Google Cloud Deploy Service architecture.
About Skaffold profiles
You can create separate Skaffold
profiles—identified in
skaffold.yaml
, in a profiles:
stanza.
When using Skaffold profiles with Google Cloud Deploy, you might create
separate profiles for all, or some, of your targets. For example, different
profiles for dev
, staging
, and prod
.
Profiles aren't necessary in order to use Skaffold in Google Cloud Deploy,
but are useful for defining manifest customizations among your targets, for
example using different Kustomize kustomization.yaml
files per target.
Add Kustomize support to your skaffold.yaml
Integrating your Kustomize configuration with your Google Cloud Deploy/Skaffold configuration consists of the following:
Include a
kustomization.yaml
file among your configuration files.You can store your configuration files in a local directory or in a Cloud Storage bucket.
In your
skaffold.yaml
file, create adeploy
stanza for each profile.You can also have a
deploy
stanza outside of any defined profiles, if you're not using profiles or for a default deploy configuration not tied to a profile. Here's an example:apiVersion: skaffold/v2beta28 kind: Config build: artifacts: - image: leeroy-web-profiles context: leeroy-web-profiles - image: leeroy-app-profiles context: leeroy-app-profiles googleCloudBuild: projectId: ${PROJECT_ID} profiles: - name: local deploy: kustomize: paths: - leeroy-app-profiles/kubernetes/local - name: test deploy: kustomize: paths: - leeroy-app-profiles/kubernetes/test - name: staging deploy: kustomize: paths: - leeroy-app-profiles/kubernetes/staging - name: prod deploy: kustomize: paths: - leeroy-app-profiles/kubernetes/prod
The Skaffold configuration shown here has separate profiles for
test
,staging
, andprod
targets. It also shows a profile for local development. Under each profile is adeploy.kustomize
stanza with a path that points to the location of the kustomization to use for that target.
Add Helm support to your skaffold.yaml
You can use Helm to render your manifests. Google Cloud Deploy doesn't use
Helm to deploy your applications, and supports only kubectl
as a deployer.
To use Helm, you need your Helm chart or charts, stored in any location you can
reference from within your skaffold.yaml
. This can be in a file system, a
repository, possibly along with your skaffold.yaml
, or an Open Container
Initiative (OCI) repository.
To use a Helm chart, you add a helm
stanza to your
skaffold.yaml
file.
apiVersion: skaffold/v2beta28
kind: Config
build:
artifacts:
- image: skaffold-helm-image
deploy:
helm:
releases:
- name: skaffold-helm-image
chartPath: charts
The skaffold.yaml
reference
shows what's required in this helm
stanza.
Using kpt with Skaffold
We recommend that you not use kpt with Skaffold V1 in Google Cloud Deploy.
Unsupported Skaffold features
The following features of Skaffold can't be used in Google Cloud Deploy:
-
Using
--module=
to select specific modules forbuild
,render
,apply
, and so on, is not supported. Static modules are supported. In Helm, the ability to create a namespace if one doesn't exist.
What's next
Visit the Skaffold site to find out about how it works and what it can do for you.
Practice using Google Cloud Deploy with Kustomize and Skaffold profiles.
Learn how Google Cloud Deploy selects the Skaffold version to use, when the Skaffold version changes, and how to determine which version is currently in use.
Learn how to use Skaffold profiles in conjunction with advanced manifest-management tools like Helm, Kustomize, and kpt.
Try out the Skaffold profiles walkthrough.