First look at Tekton Pipelines

Kubernetes is rapidly evolving from a Docker orchestration platform to a general-purpose cloud operating system. Thanks to the operators , Kubernetes is able to initially manage the high-level concepts and business processes, which means that you no longer manage the building modules blocks, services and deployments, but instead describe the things that these building blocks can create, for example, web servers, databases data, continuous deployment, certificate management, and more.







When deployed to a Kubernetes cluster, Tekton Pipelines provides the ability to define and execute build tasks, inputs and outputs in the form of simple values ​​or complex objects such as Docker images, and combine those resources into pipelines. These new Kubernetes resources and the controllers that manage them result in a standalone CI / CD platform hosted on a Kubernetes cluster.







In this post, we'll take a look at a simple build pipeline running on MicroK8S.







Preparing a test Kubernetes cluster



In this post, I am using MicroK8S to create a Kubernetes cluster. MicroK8S is useful here because it offers a selection of official add-ons , one of which is the Docker image registry. Since our pipeline builds a Docker image, we need to host it somewhere, and the MicroK8S registry add-in provides us with this functionality with a single command:







microk8s.enable registry
      
      





We also need to enable DNS lookup from the MicroK8S cluster. This is done by enabling the DNS add-on:







microk8s.enable dns
      
      





Installing Tekton Pipelines



Installing Tekton Pipelines is done with one command kubectl



(or microk8s.kubectl



in our case):







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





We can now create Tekton resources in our Kubernetes cluster.







The "Hello World" task



, . , echo



Hello World



, ubuntu



.







YAML helloworldtask.yml



:







apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: echo-hello-world
spec:
  steps:
    - name: echo
      image: ubuntu
      command:
        - echo
      args:
        - "Hello World"
      
      





Kubernetes :







microk8s.kubectl apply -f helloworldtask.yml
      
      





, , - . , Tekton .







YAML helloworldtaskrun.yml



:







apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
  name: echo-hello-world-task-run
spec:
  taskRef:
    name: echo-hello-world
      
      





Kubernetes :







microk8s.kubectl apply -f helloworldtaskrun.yml
      
      





Docker



hello world, Tekton, Docker. , RandomQuotes.







. .







, , β€” Git, . , git, URL- , :







apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: randomquotes-git
spec:
  type: git
  params:
    - name: revision
      value: master
    - name: url
      value: https://github.com/OctopusSamples/RandomQuotes-Java.git
      
      





Docker, . MicroK8S, Docker http://registry.container-registry.svc.cluster.local:5000.







image



, Docker, registry.container-registry.svc.cluster.local:5000/randomquotes



:







apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: randomquotes-image
spec:
  type: image
  params:
    - name: url
      value: registry.container-registry.svc.cluster.local:5000/randomquotes
      
      





Docker, Docker .







Docker Docker . Kubernetes Docker, : Docker Docker?







, , Docker CLI , - Docker. , umoci Docker, Kaniko Buildah Docker Docker Podman Docker.







Kaniko Tekton, Docker Docker, Kubernetes. YAML :







apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: build-docker-image-from-git-source
spec:
  inputs:
    resources:
      - name: docker-source
        type: git
    params:
      - name: pathToDockerFile
        type: string
        description: The path to the dockerfile to build
        default: /workspace/docker-source/Dockerfile
      - name: pathToContext
        type: string
        description:
          The build context used by Kaniko
          (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)
        default: /workspace/docker-source
  outputs:
    resources:
      - name: builtImage
        type: image
  steps:
    - name: build-and-push
      image: gcr.io/kaniko-project/executor:v0.17.1
      # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential
      env:
        - name: "DOCKER_CONFIG"
          value: "/tekton/home/.docker/"
      command:
        - /kaniko/executor
      args:
        - --dockerfile=$(inputs.params.pathToDockerFile)
        - --destination=$(outputs.resources.builtImage.url)
        - --context=$(inputs.params.pathToContext)
      
      





.







, , .







git



:







inputs:
    resources:
      - name: docker-source
        type: git
      
      





image



:







outputs:
  resources:
    - name: builtImage
      type: image
      
      





, , Docker:







spec:
  inputs:
    params:
      - name: pathToDockerFile
        type: string
        description: The path to the dockerfile to build
        default: /workspace/docker-source/Dockerfile
      - name: pathToContext
        type: string
        description:
          The build context used by Kaniko
          (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)
        default: /workspace/docker-source
      
      





, /workspace/docker-source



β€” , git



, docker-source



, .







, Docker. , gcr.io/kaniko-project/executor:v0.17.1



image, Kaniko:







spec:
  steps:
    - name: build-and-push
      image: gcr.io/kaniko-project/executor:v0.17.1
      # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential
      env:
        - name: "DOCKER_CONFIG"
          value: "/tekton/home/.docker/"
      command:
        - /kaniko/executor
      args:
        - --dockerfile=$(inputs.params.pathToDockerFile)
        - --destination=$(outputs.resources.builtImage.url)
        - --context=$(inputs.params.pathToContext)
      
      





, . docker-source



randomquotes-git



, builtImage β€” randomquotes-image



.







:







apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
  name: build-docker-image-from-git-source-task-run
spec:
  taskRef:
    name: build-docker-image-from-git-source
  inputs:
    resources:
      - name: docker-source
        resourceRef:
          name: randomquotes-git
    params:
      - name: pathToDockerFile
        value: Dockerfile
      - name: pathToContext
        value: /workspace/docker-source
  outputs:
    resources:
      - name: builtImage
        resourceRef:
          name: randomquotes-image
      
      







Tekton . Tekton.







Tekton CLI , kubectl



, MicroK8S microk8s.kubectl



. kubectl



β€” , MicroK8S kubectl



:







sudo microk8s.kubectl config view --raw > $HOME/.kube/config
      
      





:







tkn taskrun logs build-docker-image-from-git-source-task-run
      
      











Tekton?



Docker, Tekton . Docker, .







Kubernetes . , , ?







, Tekton , . tkn



CLI , kubectl



, . kubectl create -f taskrun.yml



, .







, CI.













, Tekton β€” . Jenkins X OpenShift Pipelines β€” , Tekton.









Kubernetes , , , , , . , Kubernetes CI , , Kubernetes.







, Jenkins X OpenShift Pipelines, Tekton . Tekton , , , , .








All Articles