Tutorial to run a basic pipeline using tektoncd/pipeline

This tutorial will run a basic pipeline which builds an image from source code, push it to dockerhub and deploy to the cluster.

Requirements

  1. minikube

  2. kubectl

  3. DockerHub Account

  4. tektoncd-pipeline

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

Tutorial

Assuming your minikube cluster is up with tektoncd/pipeline installed

  1. Clone the repository and move to directory

git clone https://github.com/piyush-garg/tekton-tutorial.git
cd tekton-tutorial
  1. Update the docker secret file with your credentials

vi prep/dockersecret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: docker-auth
  annotations:
    tekton.dev/docker-0: https://index.docker.io
type: kubernetes.io/basic-auth
data:
  username:
  password:

Set username and password

  • echo -n dockerHubUsername | base64 e.g. echo -n sthaha | base64
  • echo -n dockerHubPassword | base64 -w 0
  1. Apply Secret for Docker

    kubectl apply -f resource-descriptors/dockersecret.yaml
  2. Create Service Account to use docker secret

    kubectl apply -f resource-descriptors/serviceaccount.yaml
  3. Create Role and Role Bindings for service account to access pods, deployments and services api

    kubectl apply -f resource-descriptors/role.yaml
    kubectl apply -f resource-descriptors/rolebinding.yaml
  4. Update the Pipeline Image Resources

    Edit the Pipeline Resource of Web Image and App image with your Docker Hub username.

    vi resources/pipelineResourceImageWeb.yaml

    Provide DockerHub username here

          value: docker.io/DockerHubUsername/test-web

    Do the same for pipelineResourceImageApp.yaml

  5. Create all the pipeline resources required for pipeline

    kubectl apply -f resource-descriptors/pipelineResourceImageWeb.yaml
    kubectl apply -f resource-descriptors/pipelineResourceImageApp.yaml
    kubectl apply -f resource-descriptors/pipelineResourceGit.yaml
  6. Create task required for pipeline

    kubectl apply -f resource-descriptors/taskpush.yaml
    kubectl apply -f resource-descriptors/taskdeploy.yaml
  7. Create pipeline and create first instance of pipeline using pipeline run

    kubectl apply -f resource-descriptors/pipeline.yaml
    kubectl apply -f resource-descriptors/pipelinerun.yaml

    This will build both the app and web dockerfile, push to github and apply the kubernetes yaml for both web and app as specified in github-repo https://github.com/piyush-garg/test-go

    It will create Deployment and Service for both web and app

  8. Wait till both pods get in running state and access the service.

    kubectl get pods -w

    Wait till both web and app pod are in running state.

    Hit the service to access the application

    curl $(minikube service web --url)

Thanks for trying out