Tekton Triggers 实现全自动化的Source to Image Deploy to K8S Cluster Pipeline的运行【二十二】
实验所需文件
#文件列表
├── 01-gitlab-token-secret.yaml
├── 02-gitlab-eventlistener-rbac.yaml
├── 02-gitlab-eventlistener-rbac.yaml.bak
├── 03-task-deploy-to-cluster-rbac.yaml
├── 04-pvc-manen-cache.yaml
├── 05-tasks-source-to-image.yaml
├── 06-pipeline-source-to-image.yaml
├── 07-gitlab-push-binding.yaml
├── 08-gitlab-triggertemplate-s2i.yaml
├── 09-gitlab-eventlistener-s2i.yaml
├── .docker
│ └── config.json
创建harbor凭据用于推送镜像
#Secret:创建 使用Kaniko登陆Harbor凭据变成 K8S Secret
#Harbor部署参考《Harbor 部署HTTPS 以及 containerd 连接Harbor配置》
docker login harbor.magedu.net
将/root/.docker/config.json内容复制到以下文件
cd /root/KnativeSrc/tekton-and-argocd-in-practise-main/04-tekton-pipeline-in-practise/02-s2i-push-to-dockerhub
mkdir .docker/
[root@xianchaomaster1 .docker]# pwd
/root/KnativeSrc/tekton-and-argocd-in-practise-main/04-tekton-pipeline-in-practise/02-s2i-push-to-dockerhub/.docker
[root@xianchaomaster1 .docker]# cat .docker/config.json
{
"auths": {
"harbor.magedu.net": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
}
}
}
示例:kubectl create secret generic docker-config --from-file=<path to .docker/config.json>
[root@xianchaomaster1 02-s2i-push-to-dockerhub]# cd /root/KnativeSrc/tekton-and-argocd-in-practise-main/04-tekton-pipeline-in-practise/02-s2i-push-to-dockerhub
[root@xianchaomaster1 02-s2i-push-to-dockerhub]# kubectl create secret generic docker-config --from-file=.docker/config
[root@xianchaomaster1 02-s2i-push-to-dockerhub]# kubectl get secret
NAME TYPE DATA AGE
docker-config Opaque 1 7h47m
[root@xianchaomaster1 02-s2i-push-to-dockerhub]# kubectl describe secret
Name: docker-config
Namespace: default
Labels: <none>
Annotations: <none>
Type: Opaque
Data
====
config.json: 149 bytes
01-gitlab-token-secret.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 01-gitlab-token-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: gitlab-webhook-token
type: Opaque
stringData:
# Generated by command "openssl rand -base64 12"
webhookToken: "DXeqvozMlTA67aQB"
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get secret
NAME TYPE DATA AGE
docker-config Opaque 1 45h
gitlab-webhook-token Opaque 1 7h24m
02-gitlab-eventlistener-rbac.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 02-gitlab-eventlistener-rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: tekton-triggers-gitlab-sa
secrets:
- name: gitlab-webhook-token
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tekton-triggers-gitlab-minimal
rules:
# Permissions for every EventListener deployment to function
- apiGroups: ["triggers.tekton.dev"]
resources: ["eventlisteners", "triggerbindings", "triggertemplates", "clusterinterceptors", "clustertriggerbindings" , "triggers" , "interceptors"]
verbs: ["get", "list", "watch","create"]
- apiGroups: [""]
# secrets are only needed for Github/Gitlab interceptors, serviceaccounts only for per trigger authorization
resources: ["configmaps", "secrets", "serviceaccounts"]
verbs: ["get", "list", "watch","create"]
# Permissions to create resources in associated TriggerTemplates
- apiGroups: ["tekton.dev"]
resources: ["pipelineruns", "pipelineresources", "taskruns"]
verbs: ["get", "list", "watch","create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: tekton-triggers-gitlab-binding
subjects:
- kind: ServiceAccount
name: tekton-triggers-gitlab-sa
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: tekton-triggers-gitlab-minimal
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tekton-triggers-gitlab-minimal
rules:
- apiGroups: ["triggers.tekton.dev"]
resources: ["eventlisteners", "triggerbindings", "triggertemplates", "clusterinterceptors", "clustertriggerbindings" , "triggers" , "interceptors"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tekton-triggers-gitlab-binding
subjects:
- kind: ServiceAccount
name: tekton-triggers-gitlab-sa
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: tekton-triggers-gitlab-minimal
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 02-gitlab-eventlistener-rbac.yaml
serviceaccount/tekton-triggers-gitlab-sa unchanged
role.rbac.authorization.k8s.io/tekton-triggers-gitlab-minimal unchanged
rolebinding.rbac.authorization.k8s.io/tekton-triggers-gitlab-binding unchanged
clusterrole.rbac.authorization.k8s.io/tekton-triggers-gitlab-minimal unchanged
clusterrolebinding.rbac.authorization.k8s.io/tekton-triggers-gitlab-binding unchanged
03-task-deploy-to-cluster-rbac.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 03-task-deploy-to-cluster-rbac.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: helloworld-admin
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: helloworld-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: helloworld-admin
namespace: default
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 03-task-deploy-to-cluster-rbac.yaml
serviceaccount/helloworld-admin unchanged
clusterrolebinding.rbac.authorization.k8s.io/helloworld-admin unchanged
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get sa
NAME SECRETS AGE
default 0 2d8h
helloworld-admin 0 35h
tekton-triggers-gitlab-sa 1 7h27m
04-pvc-manen-cache.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 04-pvc-manen-cache.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: maven-cache-02
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storageClassName: nfs-csi
volumeMode: Filesystem
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 04-pvc-manen-cache.yaml
persistentvolumeclaim/maven-cache-02 configured
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
maven-cache-02 Bound pvc-1fb661df-6438-4a52-a8d8-2e741222bc60 5Gi RWX nfs-csi 46h
pvc-4a0eeb35c2-affinity-assistant-92f700dc5d-0 Terminating pvc-8a8117d4-2a2e-400d-9962-c7934673e000 1Gi RWO nfs-csi 34h
pvc-nfs-dynamic Bound pvc-fc2c40e1-6681-46b8-9030-b11c1ffbf731 10Gi RWX nfs-csi 46h
05-tasks-source-to-image.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 05-tasks-source-to-image.yaml
# Maintainer: MageEdu "<mage@magedu.com>"
# Version: v1.0.1
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: git-clone
spec:
description: Clone the code repository to the workspace.
params:
- name: git-repo-url
type: string
description: git repository url to clone
- name: git-revision
type: string
description: git revision to checkout (branch, tag, sha, ref)
workspaces:
- name: source
description: The git repo will be cloned onto the volume backing this workspace
steps:
- name: git-clone
image: alpine/git:v2.36.1
script: |
git clone -v $(params.git-repo-url) $(workspaces.source.path)/source
cd $(workspaces.source.path)/source && git reset --hard $(params.git-revision)
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-to-package
spec:
description: build application and package the files to image
workspaces:
- name: source
description: The git repo that cloned onto the volume backing this workspace
steps:
- name: build
image: maven:3.8-openjdk-11-slim
workingDir: $(workspaces.source.path)/source
volumeMounts:
- name: m2
mountPath: /root/.m2
script: mvn clean install
volumes:
- name: m2
persistentVolumeClaim:
claimName: maven-cache-02
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: generate-build-id
spec:
params:
- name: version
description: The version of the application
type: string
results:
- name: datetime
description: The current date and time
- name: buildId
description: The build ID
steps:
- name: generate-datetime
image: ikubernetes/admin-box:v1.2
script: |
#!/usr/bin/env bash
datetime=`date +%Y%m%d-%H%M%S`
echo -n ${datetime} | tee $(results.datetime.path)
- name: generate-buildid
image: ikubernetes/admin-box:v1.2
script: |
#!/usr/bin/env bash
buildDatetime=`cat $(results.datetime.path)`
buildId=$(params.version)-${buildDatetime}
echo -n ${buildId} | tee $(results.buildId.path)
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: image-build-and-push
spec:
description: package the application files to image
params:
- name: dockerfile
description: The path to the dockerfile to build (relative to the context)
default: Dockerfile
- name: image-url
description: Url of image repository
- name: image-tag
description: Tag to apply to the built image
default: latest
workspaces:
- name: source
- name: dockerconfig
optional: true
mountPath: /kaniko/.docker
steps:
- name: image-build-and-push
image: anjia0532/kaniko-project.executor:v1.9.1-debug
securityContext:
runAsUser: 0
env:
- name: DOCKER_CONFIG
value: /kaniko/.docker
command:
- /kaniko/executor
args:
- --dockerfile=$(params.dockerfile)
- --context=$(workspaces.source.path)/source
- --destination=$(params.image-url):$(params.image-tag)
- --skip-tls-verify
- --insecure
- --insecure-pull
- --skip-tls-verify-pull
- --registry-mirror=harbor.magedu.net
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: deploy-using-kubectl
spec:
workspaces:
- name: source
description: The git repo
params:
- name: deploy-config-file
description: The path to the yaml file to deploy within the git source
- name: image-url
description: Image name including repository
- name: image-tag
description: Image tag
steps:
- name: update-yaml
image: alpine:3.16
command: ["sed"]
args:
- "-i"
- "-e"
- "s@__IMAGE__@$(params.image-url):$(params.image-tag)@g"
- "$(workspaces.source.path)/source/deploy/$(params.deploy-config-file)"
- name: run-kubectl
image: lachlanevenson/k8s-kubectl
command: ["kubectl"]
args:
- "apply"
- "-f"
- "$(workspaces.source.path)/source/deploy/$(params.deploy-config-file)"
---
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 05-tasks-source-to-image.yaml
task.tekton.dev/git-clone configured
task.tekton.dev/build-to-package configured
task.tekton.dev/generate-build-id configured
task.tekton.dev/image-build-and-push configured
task.tekton.dev/deploy-using-kubectl configured
[root@xianchaomaster1 03-trigger-gitlab]# tkn task list
NAME DESCRIPTION AGE
git-clone Clone the code repo... 1 day ago
build-to-package build application a... 1 day ago
generate-build-id 1 day ago
image-build-and-push package the applica... 1 day ago
deploy-using-kubectl 1 day ago
06-pipeline-source-to-image.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 06-pipeline-source-to-image.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: source-to-image
spec:
params:
- name: git-repo-url
type: string
description: git repository url to clone
- name: git-revision
type: string
description: git revision to checkout (branch, tag, sha, ref)
default: main
- name: image-build-context
description: The path to the build context, used by Kaniko - within the workspace
default: .
- name: image-url
description: Url of image repository
- name: version
description: The version of the application
type: string
default: "v0.9"
- name: deploy-config-file
description: The path to the yaml file to deploy within the git source
default: all-in-one.yaml
#results:
# - name: datetime
# description: The current date and time
# - name: buildId
# description: The build ID
workspaces:
- name: codebase
- name: docker-config
tasks:
- name: git-clone
taskRef:
name: git-clone
params:
- name: git-repo-url
value: "$(params.git-repo-url)"
- name: git-revision
value: "$(params.git-revision)"
workspaces:
- name: source
workspace: codebase
- name: build-to-package
taskRef:
name: build-to-package
workspaces:
- name: source
workspace: codebase
runAfter:
- git-clone
- name: generate-build-id
taskRef:
name: generate-build-id
params:
- name: version
value: "$(params.version)"
runAfter:
- git-clone
- name: image-build-and-push
taskRef:
name: image-build-and-push
params:
- name: image-url
value: "$(params.image-url)"
- name: image-tag
value: "$(tasks.generate-build-id.results.buildId)"
workspaces:
- name: source
workspace: codebase
- name: dockerconfig
workspace: docker-config
runAfter:
- generate-build-id
- build-to-package
- name: deploy-to-cluster
taskRef:
name: deploy-using-kubectl
workspaces:
- name: source
workspace: codebase
params:
- name: deploy-config-file
value: $(params.deploy-config-file)
- name: image-url
value: $(params.image-url)
- name: image-tag
value: "$(tasks.generate-build-id.results.buildId)"
runAfter:
- image-build-and-push
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 06-pipeline-source-to-image.yaml
pipeline.tekton.dev/source-to-image configured
[root@xianchaomaster1 03-trigger-gitlab]# tkn pipeline list
NAME AGE LAST RUN STARTED DURATION STATUS
source-to-image 1 day ago s2i-buildid-run-00003 1 day ago 2m58s Succeeded
volume-share 1 day ago volume-share-run-xxxx 1 day ago 26s Succeeded
07-gitlab-push-binding.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 07-gitlab-push-binding.yaml
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
name: s2i-binding
spec:
params:
- name: git-revision
value: $(body.checkout_sha)
- name: git-repo-url
value: $(body.repository.git_http_url)
- name: image-url
value: harbor.magedu.net/birkhoffxia/spring-boot-helloworld
- name: version
value: v0.9
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 07-gitlab-push-binding.yaml
triggerbinding.triggers.tekton.dev/s2i-binding created
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get tb
NAME AGE
s2i-binding 7s
08-gitlab-triggertemplate-s2i.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 08-gitlab-triggertemplate-s2i.yaml
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: s2i-tt
spec:
params: # 定义参数
- name: git-revision
- name: git-repo-url
- name: image-url
- name: version
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: s2i-trigger-run- # TaskRun 名称前缀
spec:
serviceAccountName: default
pipelineRef:
name: source-to-image
taskRunSpecs:
- pipelineTaskName: deploy-to-cluster
taskServiceAccountName: helloworld-admin
params:
- name: git-repo-url
value: $(tt.params.git-repo-url)
- name: git-revision
value: $(tt.params.git-revision)
- name: image-url
value: $(tt.params.image-url)
- name: version
value: $(tt.params.version)
workspaces:
- name: codebase
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: nfs-csi
- name: docker-config
secret:
secretName: docker-config
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 08-gitlab-triggertemplate-s2i.yaml
triggertemplate.triggers.tekton.dev/s2i-tt created
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get tt
NAME AGE
s2i-tt 7s
09-gitlab-eventlistener-s2i.yaml
[root@xianchaomaster1 03-trigger-gitlab]# cat 09-gitlab-eventlistener-s2i.yaml
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: s2i-listener
spec:
serviceAccountName: tekton-triggers-gitlab-sa
triggers:
- name: gitlab-push-events-trigger
interceptors:
- ref:
name: "gitlab"
params:
- name: "secretRef"
value:
secretName: gitlab-webhook-token
secretKey: webhookToken
- name: "eventTypes"
value:
- "Push Hook"
- "Tag Push Hook"
- "Merge Request Hook"
bindings:
- ref: s2i-binding
template:
ref: s2i-tt
[root@xianchaomaster1 03-trigger-gitlab]# kubectl apply -f 09-gitlab-eventlistener-s2i.yaml
eventlistener.triggers.tekton.dev/s2i-listener created
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get eventlistener
NAME ADDRESS AVAILABLE REASON READY REASON
s2i-listener http://el-s2i-listener.default.svc.cluster.local:8080 True MinimumReplicasAvailable True
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get pods
NAME READY STATUS RESTARTS AGE
el-s2i-listener-775c7745db-gcsrz 1/1 Running 0 67s
配置Webhooks
#配置地址:http://el-s2i-listener.default.svc.cluster.local:8080
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get eventlistener
NAME ADDRESS AVAILABLE REASON READY REASON
s2i-listener http://el-s2i-listener.default.svc.cluster.local:8080 True MinimumReplicasAvailable True
#Secret令牌 DXeqvozMlTA67aQB
[root@xianchaomaster1 03-trigger-gitlab]# cat 01-gitlab-token-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: gitlab-webhook-token
type: Opaque
stringData:
# Generated by command "openssl rand -base64 12"
webhookToken: "DXeqvozMlTA67aQB"

手动触发 看是否成功


[root@xianchaomaster1 03-trigger-gitlab]# kubectl get pods
NAME READY STATUS RESTARTS AGE
spring-boot-helloworld-66cf7f78dc-c4dfr 1/1 Running 0 33s
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get deploy -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
spring-boot-helloworld 1/1 1 1 36h spring-boot-helloworld harbor.magedu.net/birkhoffxia/spring-boot-helloworld:v0.9-20230715-151703 app=spring-boot-helloworld
# 实验本地代码推送事件 触发事件
为了访问服务不中断 多增加服务
将服务手动 增到4个pod 增加服务,并且一致访问 看版本信息
[root@xianchaomaster1 03-trigger-gitlab]# kubectl scale deployment spring-boot-helloworld --replicas=4
deployment.apps/spring-boot-helloworld scaled
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
el-gitlab-event-listener-7cf6488ffd-fxwlp 1/1 Running 0 7h54m 10.244.121.14 xianchaonode1 <none> <none>
el-s2i-listener-775c7745db-gcsrz 1/1 Running 0 16m 10.244.121.2 xianchaonode1 <none> <none>
gitlab-trigger-run-zvc7q-pod 0/2 Completed 0 7h39m 10.244.121.9 xianchaonode1 <none> <none>
s2i-buildid-run-00003-build-to-package-pod 0/1 Completed 0 35h 10.244.121.11 xianchaonode1 <none> <none>
s2i-buildid-run-00003-deploy-to-cluster-pod 0/2 Completed 0 35h 10.244.121.9 xianchaonode1 <none> <none>
s2i-buildid-run-00003-generate-build-id-pod 0/2 Completed 0 35h 10.244.121.44 xianchaonode1 <none> <none>
s2i-buildid-run-00003-git-clone-pod 0/1 Completed 0 35h 10.244.121.15 xianchaonode1 <none> <none>
s2i-buildid-run-00003-image-build-and-push-pod 0/1 Completed 0 35h 10.244.121.20 xianchaonode1 <none> <none>
s2i-trigger-run-d74ns-build-to-package-pod 0/1 Completed 0 9m44s 10.244.121.6 xianchaonode1 <none> <none>
s2i-trigger-run-d74ns-deploy-to-cluster-pod 0/2 Completed 0 7m49s 10.244.121.21 xianchaonode1 <none> <none>
s2i-trigger-run-d74ns-generate-build-id-pod 0/2 Completed 0 9m43s 10.244.121.60 xianchaonode1 <none> <none>
s2i-trigger-run-d74ns-git-clone-pod 0/1 Completed 0 9m52s 10.244.121.17 xianchaonode1 <none> <none>
s2i-trigger-run-d74ns-image-build-and-push-pod 0/1 Completed 0 9m26s 10.244.121.16 xianchaonode1 <none> <none>
spring-boot-helloworld-66cf7f78dc-8szhf 1/1 Running 0 26s 10.244.121.56 xianchaonode1 <none> <none>
spring-boot-helloworld-66cf7f78dc-c4dfr 1/1 Running 0 7m42s 10.244.121.38 xianchaonode1 <none> <none>
spring-boot-helloworld-66cf7f78dc-tcrs7 1/1 Running 0 26s 10.244.121.22 xianchaonode1 <none> <none>
spring-boot-helloworld-66cf7f78dc-tx2nd 1/1 Running 0 26s 10.244.121.3 xianchaonode1 <none> <none>
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get deploy -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
el-gitlab-event-listener 1/1 1 1 7h54m event-listener gcr.lank8s.cn/tekton-releases/github.com/tektoncd/triggers/cmd/eventlistenersink:v0.24.0@sha256:77519cdc53bdefa393f700fb0e5891212c71411f09b4c261ea78c8d00cb6e831 app.kubernetes.io/managed-by=EventListener,app.kubernetes.io/part-of=Triggers,eventlistener=gitlab-event-listener
el-s2i-listener 1/1 1 1 16m event-listener gcr.lank8s.cn/tekton-releases/github.com/tektoncd/triggers/cmd/eventlistenersink:v0.24.0@sha256:77519cdc53bdefa393f700fb0e5891212c71411f09b4c261ea78c8d00cb6e831 app.kubernetes.io/managed-by=EventListener,app.kubernetes.io/part-of=Triggers,eventlistener=s2i-listener
spring-boot-helloworld 4/4 4 4 36h spring-boot-helloworld harbor.magedu.net/birkhoffxia/spring-boot-helloworld:v0.9-20230715-151703 app=spring-boot-helloworld
[root@xianchaomaster1 03-trigger-gitlab]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
demoapp ExternalName <none> knative-local-gateway.istio-system.svc.cluster.local 80/TCP 2d
demoapp-00001 ClusterIP 10.107.153.199 <none> 80/TCP,443/TCP 2d
demoapp-00001-private ClusterIP 10.104.114.35 <none> 80/TCP,443/TCP,9090/TCP,9091/TCP,8022/TCP,8012/TCP 2d
el-gitlab-event-listener ClusterIP 10.100.187.226 <none> 8080/TCP,9000/TCP 7h56m
el-s2i-listener ClusterIP 10.110.95.77 <none> 8080/TCP,9000/TCP 18m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d9h
spring-boot-helloworld NodePort 10.100.26.239 <none> 80:31306/TCP 36h
[root@xianchaomaster1 03-trigger-gitlab]# curl 10.100.26.239
Hello Spring Boot 2.0!
[root@xianchaomaster1 03-trigger-gitlab]# kubectl run client-$RANDOM --image ikubernetes/admin-box:v1.2 --restart=Never -it --rm --command -- /bin/bash
If you dont see a command prompt, try pressing enter.
root@client-7072 /# host -t A spring-boot-helloworld.default
spring-boot-helloworld.default.svc.cluster.local has address 10.100.26.239
root@client-7072 /# while true; do curl spring-boot-helloworld.default/version; sleep .5;done
version 0.9.6!version 0.9.6!version 0.9.6!version 0.9.6!version 0.9.6!version 0.9.6!version 0.9.6!version 0.9.6!version 0.9.6!version 0.9.6!^C
手动clone代码 修改 上传push代码 触发事件
[root@xianchaonode1 ~]# git clone http://10.110.158.21/root/spring-boot-helloWorld.git
Cloning into 'spring-boot-helloWorld'...
remote: Enumerating objects: 256, done.
remote: Total 256 (delta 0), reused 0 (delta 0), pack-reused 256
Receiving objects: 100% (256/256), 35.06 KiB | 0 bytes/s, done.
Resolving deltas: 100% (73/73), done.
[root@xianchaonode1 ~]# vim spring-boot-helloWorld/src/main/java/com/neo/controller/HelloWorldController.java
return "Birkhoff 2023-07-15 success vistor this version 0.9.8!\n";
[root@xianchaonode1 ~]# vim spring-boot-helloWorld/pom.xml
<version>0.9.7-SNAPSHOT</version>
[root@xianchaonode1 ~]# vim spring-boot-helloWorld/deploy/all-in-one.yaml
replicas: 4
[root@xianchaonode1 ~]# git status
fatal: Not a git repository (or any of the parent directories): .git
[root@xianchaonode1 ~]# cd spring-boot-helloWorld/
[root@xianchaonode1 spring-boot-helloWorld]# git status
# On branch main
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: deploy/all-in-one.yaml
# modified: pom.xml
# modified: src/main/java/com/neo/controller/HelloWorldController.java
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@xianchaonode1 spring-boot-helloWorld]# git config --global user.name birkhoff
[root@xianchaonode1 spring-boot-helloWorld]# git config --global user.email 123@qq.com
[root@xianchaonode1 spring-boot-helloWorld]# git add .
[root@xianchaonode1 spring-boot-helloWorld]# git status
# On branch main
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: deploy/all-in-one.yaml
# modified: pom.xml
# modified: src/main/java/com/neo/controller/HelloWorldController.java
#
[root@xianchaonode1 spring-boot-helloWorld]# git commit -m "Birkhoff update version to v0.9.7"
[main 1efee9a] Birkhoff update version to v0.9.7
3 files changed, 3 insertions(+), 3 deletions(-)
[root@xianchaonode1 spring-boot-helloWorld]# git push origin
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Username for 'http://10.110.158.21': root
Password for 'http://root@10.110.158.21':
Counting objects: 23, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (12/12), 931 bytes | 0 bytes/s, done.
Total 12 (delta 5), reused 0 (delta 0)
To http://10.110.158.21/root/spring-boot-helloWorld.git
fecc8c2..1efee9a main -> main

日志访问是否正常访问
[root@xianchaomaster1 03-trigger-gitlab]# kubectl run client-$RANDOM --image ikubernetes/admin-box:v1.2 --restart=Never -it --rm --command -- /bin/bash
root@client-7072 /# while true; do curl spring-boot-helloworld.default/version; sleep .5;done
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
Birkhoff 2023-07-15 success vistor this version 0.9.8!
^C
root@client-7072 /#


浙公网安备 33010602011771号