Running a local Kubernetes cluster and setting up Tekton pipeline

Sudha Subramaniam
5 min readMar 9, 2023

--

In this post I intend to explain how to set up Kubernetes on your local windows machine and then how to set up tekton pipeline for CI/CD.so we can play around with it easily

Docker Desktop is the easiest way to run Kubernetes on our local machine — it gives us a fully certified Kubernetes cluster and manages all the components for us and it is an application for Mac, Linux, or Windows environment that enables us to build and share containerized applications.

If you have docker desktop installed in your machine then Installing kunbernates is simple.

Pre-requisites

  • Docker desktop

Verify the docker installation by using below command and check Docker desktop app is installed

docker version

we are going to perform below tasks as part this post

Installing kubernates

Installing kubectl

Install Kubernetes Dashboard

Containerize simple Application

Deploy the Application to Kubernetes

tekton cli installation

tekton pipeline installation

tekton dashboard installation

create tekon pipeline

Installing Kubernetes

Open Docker desktop and Go to settings then select Kubernetes check Enable Kubernetes →Apply and restart. please allow sometime for the installation to complete and then we will try to install kubectl

Installing kubectl

The Kubernetes command-line interface tool, allows us to run commands against Kubernetes clusters. we can use kubectl to deploy applications, inspect and manage cluster resources, and view logs

Now we can install kubectl using below link

https://dl.k8s.io/release/v1.26.0/bin/windows/amd64/kubectl.exe

after installing verify the installation by using below command

kubectl version

Server version refers to the version of Kubernetes API server.
Client version refers to the version of kubectl CLI.

Install Kubernetes Dashboard

Kubernates dashboard provides GUI to manage/view pods,nodes, deployments,etc., To install dashboard we can follow below steps

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

or we can download yaml and run as below

kubectl apply -f C:\Users\Admin\Desktop\kubernates_dashboard.yaml

kubernates dashboard yaml can be found in the repo https://github.com/sudhast1910/k8s-tekon-pipeline-ss

then run the command kubectl proxy to view dashboard

Below is the url to access the dashboard

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

Access the dashboard

The dashboard can be accessed with tokens in two ways: the first is by using the default token created during Kubernetes installation, and the second method is by creating users, giving them permissions, and then receiving the generated token.

Token can be Static Token, Service Account Token, OpenID Connect Token. With kubectl, we can get an service account (eg. deployment controller) created in kubernetes by default.

run below commands to get token

kubectl -n kube-system get secret

kubectl -n kube-system describe secret deployment-controller-token-frsqa

copy the token displayed and use the same to login to dashboard and below is the dashboard workload view

Containerize the Application

There are multiple ways to containerize the app as it’s a spring boot application we can use plugin to create an image

gradlew bootBuildImage

then we can run container locally using below command to verify app is running before deploying in kubernates

docker run -p 8080:8080 demo:0.0.1-SNAPSHOT

We can push this image to docker hub

docker login — username sudhaxxxxxxx

docker push springsudha/testapp

Deploy the Application to Kubernetes

Kubernetes is a popular container orchestration framework. It enables us to scale and manage large clusters of container.

To deploy application in kubernates we need to create deployment , Deployment provides declarative updates for Pods and ReplicaSets and Service is used to expose groups of Pods over a network.

kubectl create namespace spring-kube
kubectl config set-context — current — namespace=spring-kube

kubectl create deployment testdeploy1 — image=geshadock/springguides_demo — dry-run=client -o=yaml > deployment_ns.yaml

kubectl create service clusterip testdeploy1 — tcp=8080:8080 — dry-run=client -o=yaml >> service.yaml

kubectl apply -f deployment_ns.yaml

kubectl apply -f service.yaml

repo https://github.com/sudhast1910/k8s-tekon-pipeline-ss contains same set of yaml files

Health of the deployed application

Tekton cli installation

Tekton is an open-source framework for building and running CI/CD pipelines as code. let us first install tekton cli.

The reason for installing tekton cli is to install tekton pipeline using cli and to interact with tekton components, I have downloaded exe file and installed from below link

https://tekton.dev/docs/cli/

Tekon pipeline installation

Below command is used to install tekton pipeline

kubectl apply — filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml

Monitor the installation

kubectl get pods — namespace tekton-pipelines — watch

verify the installation using tkn version command

Tekton dashboard installation

run the bellow command to install tekton dashboard

E:\kubernets\pipeline>kubectl apply — filename https://storage.googleapis.com/tekton-releases/dashboard/latest/release-full.yaml

kubectl port-forward -n tekton-pipelines service/tekton-dashboard 9097:9097

We can access tekton dashboaed using http://localhost:9097/#/namespaces/spring-kube/pipelines

Creating pipeline

Let us create simple clone task and invoked by below pipeline

kubectl apply -f clone_task.yaml -n spring-kube

output of above command - task.tekton.dev/git-clone-repo created

kubectl apply -f pipeline.yaml -n spring-kube

output of above command -pipeline.tekton.dev/cat-branch-readme configured

kubectl apply -f pipelinerun.yaml -n spring-kube

output of above command -pipelinerun.tekton.dev/git-clone-readme created

repo https://github.com/sudhast1910/k8s-tekon-pipeline-ss contains sample task and pipeline yaml files

Tasks

Pipeline run log:

Rerunning the pipeline can be done using below option

kubectl get pipelines
kubectl get pipelinerun
kubectl get pipelinerun git-clone-checking-out-a-branch

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response