Kubernetes Build and deploy with flux2+helm+tekton+kaniko

PART 1: tekton

Arpan Chatterjee
3 min readDec 23, 2020

First, we start with the installation of the required components that we will be using.

Install Tekton Build tools

  1. https://github.com/tektoncd/pipeline/blob/master/docs/install.md#installing-tekton-pipelines-on-kubernetes
  2. go to this URL to get the latest release of tekton pipelines.

Apply kubectl get po -n tekton-pipelines to check all the components are running

Install Tekton Dashboard

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

it provides a nice interface for watching the pipelines and re-running also. It also comes with a command-line tool you can use the same tool to run your pipeline resources please go through the official documentation for more info.

kubectl — namespace tekton-pipelines port-forward svc/tekton-dashboard 9097:9097

install tekton triggers it helps to create webhooks for build and push jobs

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

please go through the documentation for installing flux in your cluster

you should check all the components running before we bump into to next part.

Configuring Tekton For creating and publishing images

first, we need the required creds to push the docker image

kubectl create secret docker-registry regcred \
--docker-server=https://index.docker.io/v1/ \
--docker-username=<your-name> \
--docker-password=<your-pword> \
--docker-email=<your-email>

Github secret

apiVersion: v1
kind: Secret
metadata:
name: github-secrets
type: Opaque
data:
token: github_personal_access_token_secret

Service account to push to docker hub

apiVersion: v1kind: ServiceAccountmetadata:name: dockerhub-serviceaccountsecrets:
- name: regcred

Now let's Move on to create the pipelines and tasks

first, we will create two pipeline resources to handle our input and output.

- -apiVersion: tekton.dev/v1alpha1kind: PipelineResourcemetadata:name: build-image-via-pipelineannotations:fluxcd.io/automated: "true"spec:type: gitparams:- name: revisionvalue: master- name: urlvalue: https://github.com/btwseeu78/demologinapp.git- -apiVersion: tekton.dev/v1alpha1kind: PipelineResourcemetadata:name: push-image-via-pipelineannotations:fluxcd.io/automated: "true"spec:type: imageparams:- name: urlvalue: linuxarpan/kanikotesting:v5

The task to actually provide params and using resources

apiVersion: tekton.dev/v1beta1kind: Taskmetadata:name: build-and-push-docker-imageannotations:fluxcd.io/automated: "false"spec:params:- name: pathToDockerFiletype: stringdescription: The Path To Docker Filedefault: $(resources.inputs.docker-source.path)/Dockerfile- name: pathToContexttype: stringdescription: the build context used by kanikodefault: $(resources.inputs.docker-source.path)resources:inputs:- name: docker-sourcetype: gitoutputs:- name: builtImagetype: imagesteps:- name: build-and-pushimage: gcr.io/kaniko-project/executor:latestargs:- - dockerfile=$(params.pathToDockerFile)- - destination=$(resources.outputs.builtImage.url)- - context=$(params.pathToContext)volumeMounts:- name: kaniko-secretmountPath: "/kaniko/.docker/"volumes:- name: kaniko-secretsecret:secretName: regcreditems:- key: .dockerconfigjsonpath: config.json

create a runner to run the task

apiVersion: tekton.dev/v1beta1kind: TaskRunmetadata:name: build-image-from-git-sourceannotations:fluxcd.io/automated: "false"spec:serviceAccountName: dockerhub-serviceaccounttaskref:name: build-and-push-docker-imageparams:- name: pathToDockerFilevalue: Dockerfileresources:inputs:- name: docker-sourceresourceRef:name: build-image-via-pipelineoutputs:- name: builtImageresourceRef:name: push-image-via-pipeline

Output

It's still beta just published to help someone if they want to start there are multiple ways to do this . I will update the cos and also add more explanation regarding all the components. In much detail also add flux and other tools like helm to create a nice ecosystem. stay tuned and please comment ask questions or suggestions I'm still new to this it will hem me learn a lot.

The indentation is kind of messed of so please go through the files in this repo they cover the YAML for task and resources.

https://github.com/btwseeu78/tektontemplates.git

--

--

Arpan Chatterjee

Learning new things .Expertise lies in kubernetes and gitops