Chapter 12. Preparing for a New Pipeline

Поднимаем новый minikube

Настраиваем для работы.


$ kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
$ kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
$ kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml
$ kubectl apply -f https://raw.githubusercontent.com/tektoncd/triggers/main/examples/rbac.yaml


Finally, you need to make one last adjustment to your cluster to be able to deploy your applications automatically. You will need to give the appropriate role to your service account so that it can access the Kubernetes API and automatically update your application. You can use the following command to do so:


$ kubectl create clusterrolebinding \
  serviceaccounts-cluster-admin \
  --clusterrole=cluster-admin \
  --group=system:serviceaccounts


$ tkn version
Client version: 0.21.0
Pipeline version: v0.28.1
Triggers version: v0.16.0


Exploring the source code


https://github.com/PacktPublishing/tekton-book-app


Форкаем.


$ cd ~/tmp/

// По https нужно еще и key настраивать
// $ git clone [email protected]:<YOUR_USERNAME>/tekton-book-app
$ git clone https://github.com/<YOUR_USERNAME>/tekton-book-app


$ cd tekton-book-app


$ npm install
$ npm start


Подключаемся еще 1 терминалом

$ gcloud cloud-shell ssh


$ curl localhost:3000
$ curl localhost:3000/add/12/10
$ curl localhost:3000/substract/10/2


$ npm run lint
$ npm run test


Building and deploying the application


$ export DOCKER_USERNAME=<YOUR_USERNAME>
$ docker build -t ${DOCKER_USERNAME}/tekton-lab-app .
$ docker login docker.io
$ docker push ${DOCKER_USERNAME}/tekton-lab-app


Deploying the application


**Не забыть заменить на свой.**


$ cat << 'EOF' | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tekton-deployment
spec:
  selector:
    matchLabels:
      app: trigger-demo
  template:
    metadata:
      labels:
        app: trigger-demo
    spec:
      containers:
      - name: tekton-pod
        image: <YOUR_USERNAME>/tekton-lab-app
        ports:
        - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: tekton-svc
spec:
  selector:
    app: trigger-demo
  ports:
  - port: 3000
    protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tekton-ingress
spec:
  rules:
  - http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: tekton-svc
            port:
              number: 3000
EOF


$ kubectl get pods
NAME                                 READY   STATUS    RESTARTS   AGE
tekton-deployment-5d5d5fd747-9dcn4   1/1     Running   0          78s


// Убеждаемся, что значение профиля установлено
$ echo ${PROFILE}
$ curl $(minikube --profile ${PROFILE} ip)


OK!


Далее нудная процедура по изменению кода и обновлению всего и вся, чтобы показать нам как все это нудно делать руками.