In the previous blog i shared how Jib, an open source tool maintained by Google accelerates the development of docker images for java based application.
But if you are doing deployment in a Kubernetes environment then you should try Skaffold, another open source container tool from google which simplifies common operational tasks that you perform when doing Kubernetes development, letting you focus on your code changes and see them rapidly reflected on your cluster.
Developers spent a good amount of time building and managing container images across registries, manually updating their Kubernetes manifests, and redeploying their applications every time they made even the smallest code changes while building Kubernetes-native applications.
Skaffold automates these tasks and let developers focus on writing and maintaining code.
A typical workflow for kubernetes development looks like this
The boxes marked in blue can be managed by Jib, details on blog
Skaffold automates this entire process.
It is designed to make local Kubernetes development easy.
It watches your code for changes and smartly builds and deploys your application to any Kubernetes providers, allowing you to focus solely on application development without having to worry about operations.
Skaffold’s central command, skaffold dev, watches local source code for changes, and rebuilds and redeploys applications to your cluster in real time.
It comes with highly optimized workflows for local and remote deployment, giving you the flexibility to develop against local Kubernetes clusters like Minikube or Kind, as well as any remote Kubernetes cluster.
Installation details of Skaffold can be found at this link.
Skaffold operates completely on the client-side, with no required components on your cluster, making it super lightweight and high-performance.
Let us see this in action by an example, by using skaffold to:
Invoke Jib to build the application, without using Dockerfile
Upload image to registry
Create pods and deploys to kubernetes cluster
Make changes to the code and see how skaffold watches those changes and rebuilds the code and deploys it at real time
For our demo , i have a simple spring boot application created and pushed to my git repo.
Skaffold uses yaml configuration to describe, how you application should be built and deployed. In our demo applications yaml
In the build.artifiacts.image we have mentioned the name of the image to be built.
Since i am using this to build and deploy on my local minikube i have mentioned build type local to the build section of skaffold.yaml
Skaffold’s deploy configuration is set through the deploy section of the skaffold.yaml. In this example we are using kubectl and our deployment and service yaml names are at the root and starts with k8s-* . It also supports helm and kustomize.
pom.xml of the demo application contains the plugin details, of Jib and the details of image name which has to be uploaded to the docker repo.
i have my minikube running
kubectl get pods to check if there are any pods running. There is none
We will now skaffold run which single command for a one-off deployment. It runs through every major phase of the Skaffold lifecycle: building your application images, tagging these images (and optionally pushing them to a remote registry), deploying your application to the target cluster, and monitoring the created resources for readiness.
Snapshot of the console where it is building the application
Building container using jib plugin and uploading to docker repository
Deploying to kubernetes cluster
Output of kubectl get pods shows all the 3 pods running
Another very important feature of skaffold is its ability to watch file changes and do live deployment to cluster. It is done using skaffold dev command
When skaffold dev is run, Skaffold will first do a full build, test and deploy of all artifacts specified in the skaffold.yaml, similar to skaffold run. Upon successful build, test and deploy, Skaffold will start watching all source file dependencies for all artifacts specified in the project. As changes are made to these source files, Skaffold will rebuild and retest the associated artifacts, and redeploy the new changes to your cluster.
To see this feature , let us run skaffold dev in one console and kubectl get pods -w in another
If you make any change in the application code, you will see in skaffold dev console window application getting redeployed
Console window running kubectl get pods -w will also show the states of the pod
To access the application you can get the url by minikube service skaffold-demo-image command
The first image of the blog showed the various workflow process or steps involved in deploying a kubernetes application . Skaffold eliminates all that and with one command you can have your application build, containerized, uploaded to registry and deployed to kubernetes cluster
It handles the workflow for building, pushing, and deploying your application, and provides building blocks for creating CI/CD pipelines
Skaffold has lot of other features worth looking at like port-forwarding for debugging, health checks and templating deployment configurations, etc.