CI CD Utility for Kubernetes Cluster SKAFFOLD
Posted By : Pranshu Sharma | 30-Sep-2019
Skaffold is a command-line device from Google that brings automation to the deployment workflow of Kubernetes applications. This tool is tailor-made to furnish developers with a journey of iteration and deployment which carefully mirrors production.
Installing Skaffold:-
The following are the prerequisites:-
1. Docker Engine
2. Docker image registry: Your docker consumer should be configured to push to an exterior docker photo repository.or you can even use any different container registry, as skaffold will study the happen file and push the docker picture in the respective registry.
3. kubectl — Kubernetes command-line tool
Installation of Skaffold:-
is a easy method considering the package deal is allotted as a binary file. You solely want to download the package, area it below your $PATH and make it executable. You can use wget or curl to pull the binary file.
Installing on Linux
Download the package:
# wget https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 -O /usr/local/bin/skaffold
Make the file executable:
# chmod +x /usr/local/bin/skaffold
DEMO
Dockerfile to be used for constructing a Docker image.
The contents of my Dockerfile are as below:
$cat Dockerfile
FROM nginx
COPY index.html /usr/share/nginx/html/
WORKDIR /usr/share/nginx/html
The content of index.html file:
$ cat index.html
Hello OODLES - Test Page
Create Kubernetes deployment
Your next step is to create a Kubernetes deployment YAML file. The contents of my file are:
$ cat demo-skaffold-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-oodles
spec:
selector:
matchLabels:
app: hello-world-oodles
template:
metadata:
labels:
app: hello-world-oodles
spec:
containers:
- name: hello-world-oodles
image: nginx-skaffold
Create Kubernetes Service
$ cat demo-skaffold-service.yaml
apiVersion: v1
kind: Service
metadata:
name: hello-world-oodles
spec:
selector:
app: hello-world-oodles
ports:
- port: 8080
protocol: TCP
targetPort: 80
type: LoadBalancer
Create Skaffold configuration
The Skaffold configuration file is the place the workflow is configured. In this file, you define the equipment you will be using and their configuration. The Skaffold configuration file used in this demo has the following content.
$ cat skaffold.yaml
apiVersion: skaffold/v1alpha2
kind: Config
build:
artifacts:
- imageName: nginx-skaffold
workspace: .
local: {}
deploy:
kubectl:
manifests:
- k8s-*
From the file definitions, it can be viewed that the Skaffold workflow has three essential phases.
1. Build
In the build phase, Skaffold builds an artifact on the usage of the device of your choice. Artifacts are Docker images that you would like to set up into your Kubernetes cluster when changes are made to them.
2. Push
In the push phase, Skaffold ensures that your photograph is uploaded to the registry referenced in the photograph name. Before jogging Skaffold you need to make sure that you are capable to push to your configured picture registry.
When the use of local Kubernetes clusters like Minikube or Docker for Desktop, the push is skipped because the photo is already handy locally.
3. Deploy
The installation step ensures that the most current artifacts are jogging in the cluster. You can use special equipment for deployment, for example, kubectl or helm. Each deployment type has parameters that allow you to define how you desire your app to be mounted and updated.
You have to run skaffold command to provoke skaffold deployment on your Kubernetes environment by the following 2 ways:-
1.
==>This will keep the build deployment in the buffer and will track the source files if any changes have occurred, it will be deployed on the k8s cluster at that instant.
#skaffold dev
2.
==>This will deploy the build once only, when the command is executed
#skaffold run -f skaffold.yml
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Pranshu Sharma
Pranshu is an RHCSA, RHCE, RHCoE(Ansible Automation) keen in python,kubernetes, docker, cloud development, DevOps and Security. His hobbies are Trekking, Chess, Reading and Adventure Sports.