Gitlab Source
[root@master ~]# git clone https://github.com/iKubernetes/k8s-gitlab.git
[root@master deploy-gitlab]# kubectl apply -f .
namespace/gitlab created
service/redis created
deployment.apps/redis created
secret/gitlab created
service/postgresql created
deployment.apps/postgresql created
service/code created
service/gitlab created
deployment.apps/gitlab created
[root@master deploy-gitlab]# kubectl get pods -n gitlab
NAME READY STATUS RESTARTS AGE
gitlab-66f876df75-m7s4z 1/1 Running 0 2m25s
postgresql-84cb88d7d4-n5q6k 1/1 Running 0 2m25s
redis-6b96797cb4-qr8xd 1/1 Running 0 2m26s
通过istio ingress暴露端口出来
[root@master istio]# kubectl apply -f .
[root@master istio]# cat destinationrule-gitlab.yaml
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: gitlab
namespace: gitlab
spec:
host: gitlab
trafficPolicy:
tls:
mode: DISABLE
---
[root@master istio]# cat gateway-gitlab.yaml
---
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: gitlab-gateway
namespace: istio-system
spec:
selector:
app: istio-ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "gitlab.yang.com"
- "code.yang.com"
---
[root@master istio]# cat virtualservice-gitlab.yaml
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: gitlab-virtualservice
namespace: gitlab
spec:
hosts:
- "gitlab.yang.com"
- "code.yang.com"
gateways:
- istio-system/gitlab-gateway
http:
- match:
- uri:
prefix: /
route:
- destination:
host: gitlab
port:
number: 80
---
做好hosts解析
10.211.55.30 code.yang.com gitlab.yang.com
[root@master istio]# kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.100.247.178 10.211.55.30 15021:30446/TCP,80:31623/TCP,443:31154/TCP 9d
istiod ClusterIP 10.99.195.197 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 9d
knative-local-gateway ClusterIP 10.111.234.134 <none> 80/TCP 2d21h
浏览器直接访问
开启允许来自web hooks和服务队本地网络的请求
设定自定义HTTPS协议Git克隆URL
新建项目
创建个人访问令牌
将令牌复制出来
glpat-iV5VH_4_6o4w6KTb9kug
[root@master k8s-gitlab]# kubectl apply -f https://github.com/knative-sandbox/eventing-gitlab/releases/download/knative-v1.8.0/gitlab.yaml
namespace/knative-sources created
serviceaccount/gitlab-controller-manager created
serviceaccount/gitlab-webhook created
clusterrole.rbac.authorization.k8s.io/gitlabsource-manager-role created
clusterrole.rbac.authorization.k8s.io/eventing-contrib-gitlab-source-observer created
clusterrolebinding.rbac.authorization.k8s.io/gitlabsource-manager-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/eventing-sources-gitlab-addressable-resolver created
clusterrolebinding.rbac.authorization.k8s.io/eventing-sources-gitlab-webhook created
clusterrole.rbac.authorization.k8s.io/gitlab-webhook created
customresourcedefinition.apiextensions.k8s.io/gitlabbindings.bindings.knative.dev created
customresourcedefinition.apiextensions.k8s.io/gitlabsources.sources.knative.dev created
service/gitlab-controller-manager-service created
deployment.apps/gitlab-controller-manager created
mutatingwebhookconfiguration.admissionregistration.k8s.io/defaulting.webhook.gitlab.sources.knative.dev created
validatingwebhookconfiguration.admissionregistration.k8s.io/validation.webhook.gitlab.sources.knative.dev created
mutatingwebhookconfiguration.admissionregistration.k8s.io/gitlabbindings.webhook.gitlab.sources.knative.dev created
secret/gitlab-webhook-certs created
service/gitlab-webhook created
deployment.apps/gitlab-webhook created
[root@master k8s-gitlab]# kubectl get pods -n knative-sources
NAME READY STATUS RESTARTS AGE
gitlab-controller-manager-5fd8cc597f-rhfkf 1/1 Running 0 2m30s
gitlab-webhook-7fb4f8c48f-h2ppj 1/1 Running 1 (43s ago) 2m30s
accessToken和secretToken都改成自己的
[root@master 05-gitlabsource-to-knative-service]# openssl rand -base64 16
E7RdUDfd+MBxbye/dygLSw==
[root@master 05-gitlabsource-to-knative-service]# cat 03-secret-token.yaml
apiVersion: v1
kind: Secret
metadata:
name: gitlabsecret
namespace: event-demo
type: Opaque
stringData:
accessToken: glpat-iV5VH_4_6o4w6KTb9kug
secretToken: E7RdUDfd+MBxbye/dygLSw
之前文档部署的event-demo
[root@master 04-apiserversource-to-knative-service]# kubectl get pods -n event-demo
NAME READY STATUS RESTARTS AGE
apiserversource-pods-event-563801d7-4ca5-41a8-ac41-ecc2234rdmcn 1/1 Running 0 5s
event-display-00001-deployment-6cdd9979bf-5vtmr 2/2 Running 0 11s
[root@master 05-gitlabsource-to-knative-service]# kubectl apply -f .
namespace/event-demo unchanged
service.serving.knative.dev/event-display configured
secret/gitlabsecret created
gitlabsource.sources.knative.dev/gitlabsource-demo created
[root@master 05-gitlabsource-to-knative-service]# cat 01-namespace.yaml
kind: Namespace
apiVersion: v1
metadata:
name: event-demo
---
[root@master 05-gitlabsource-to-knative-service]# cat 02-kservice-event-display.yaml
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
namespace: event-demo
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/min-scale: "1"
spec:
containers:
- image: ikubernetes/event_display
ports:
- containerPort: 8080
[root@master 05-gitlabsource-to-knative-service]# cat 03-secret-token.yaml
apiVersion: v1
kind: Secret
metadata:
name: gitlabsecret
namespace: event-demo
type: Opaque
stringData:
accessToken: glpat-iV5VH_4_6o4w6KTb9kug
secretToken: E7RdUDfd+MBxbye/dygLSw
[root@master 05-gitlabsource-to-knative-service]# cat 04-GitLabSource-to-knative-service.yaml
apiVersion: sources.knative.dev/v1alpha1
kind: GitLabSource
metadata:
name: gitlabsource-demo
namespace: event-demo
spec:
eventTypes:
- push_events
- issues_events
- merge_requests_events
- tag_push_events
projectUrl: http://code.gitlab.svc.cluster.local/root/myproject
sslverify: false
accessToken:
secretKeyRef:
name: gitlabsecret
key: accessToken
secretToken:
secretKeyRef:
name: gitlabsecret
key: secretToken
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
查看gitlab已经自动注入了一个webhook
查看svc和vs
[root@master 05-gitlabsource-to-knative-service]# kubectl get svc -n event-demo
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
event-display ExternalName <none> knative-local-gateway.istio-system.svc.cluster.local 80/TCP 16m
event-display-00001 ClusterIP 10.99.26.68 <none> 80/TCP,443/TCP 16m
event-display-00001-private ClusterIP 10.100.117.24 <none> 80/TCP,443/TCP,9090/TCP,9091/TCP,8022/TCP,8012/TCP 16m
gitlabsource-demo-nz85v ExternalName <none> knative-local-gateway.istio-system.svc.cluster.local 80/TCP 9m54s
gitlabsource-demo-nz85v-00001 ClusterIP 10.108.129.16 <none> 80/TCP,443/TCP 10m
gitlabsource-demo-nz85v-00001-private ClusterIP 10.103.162.193 <none> 80/TCP,443/TCP,9090/TCP,9091/TCP,8022/TCP,8012/TCP 10m
[root@master 05-gitlabsource-to-knative-service]# kubectl get vs -n event-demo
NAME GATEWAYS HOSTS AGE
event-display-ingress ["knative-serving/knative-ingress-gateway","knative-serving/knative-local-gateway"] ["event-display.event-demo","event-display.event-demo.svc","event-display.event-demo.svc.cluster.local","event-display.event-demo.yang.com"] 16m
event-display-mesh ["mesh"] ["event-display.event-demo","event-display.event-demo.svc","event-display.event-demo.svc.cluster.local"] 16m
gitlabsource-demo-nz85v-ingress ["knative-serving/knative-ingress-gateway","knative-serving/knative-local-gateway"] ["gitlabsource-demo-nz85v.event-demo","gitlabsource-demo-nz85v.event-demo.svc","gitlabsource-demo-nz85v.event-demo.svc.cluster.local","gitlabsource-demo-nz85v.event-demo.yang.com"] 10m
gitlabsource-demo-nz85v-mesh ["mesh"] ["gitlabsource-demo-nz85v.event-demo","gitlabsource-demo-nz85v.event-demo.svc","gitlabsource-demo-nz85v.event-demo.svc.cluster.local"] 10m
编辑
将gitlabsource-demo-nz85v.event-demo.svc.cluster.local复制到网址中
测试一下
是成功的
查看事件
[root@master 05-gitlabsource-to-knative-service]# kubectl logs -f event-display-00001-deployment-6cdd9979bf-5vtmr -n event-demo
我们在测试一下tag push event
可以正常看到推送
[root@node1 ~]# git clone http://code.yang.com/root/myproject.git
[root@node1 ~]# vim a.py
[root@node1 ~]# touch 2.sh
[root@node1 myproject]# git config user.name root
[root@node1 myproject]# git config --global user.name root
[root@node1 myproject]# git config --global user.email yang@yang.com
[root@node1 myproject]# git add .
[root@node1 myproject]# git commit -m "v0.1"
[main d595c35] v0.1
2 files changed, 1 insertion(+)
create mode 100644 2.sh
create mode 100644 a.py
[root@node1 myproject]# 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://code.yang.com': root
Password for 'http://root@code.yang.com':
Counting objects: 5, done.
Delta compression using up to 3 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 299 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To http://code.yang.com/root/myproject.git
db3ddca..d595c35 main -> main
也可以正常看到推送事件