赞
踩
kubectl create namespace gitlab
vim pvc-gitlab.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: gitlab
name: gitlab-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 40Gi
然后使用如下命令创建
kubectl apply -f pvc-gitlab.yaml
vim pvc-postsql.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace:gitlab
name: postsql-data
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage:5Gi
然后执行如下命令
kubectl apply -f pvc-postsql.yaml
vim pvc-redis.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: gitlab
name: redis-data
spec:
accessModes:
- ReadWriteMany
resource:
requests:
storage: 5Gi
然后执行如下命令创建供redis使用的pvc
kubectl apply -f pvc-redis.yaml
vim postsql.yaml apiVersion: apps/v1 kind: Deployment metadata: name: postgresql namespace: gitlab labels: name: postgresql spec: selector: matchLabels: name: postgresql template: metadata: labels: name: postgresql spec: containers: - name: postgresql image: sameersbn/postgresql:10 imagePullPolicy: IfNotPresent env: - name: DB_USER value: gitlab - name: DB_PASS value: gitlab - name: DB_NAME value: gitlab_production - name: DB_EXTENSION value: pg_trgm ports: - name: postgres containerPort: 5432 volumeMounts: - mountPath: /var/lib/postgresql name: data livenessProbe: exec: command: - pg_isready - -h - localhost - -U - postgres initialDelaySeconds: 30 timeoutSeconds: 5 readinessProbe: exec: command: - pg_isready - -h - localhost - -U - postgres initialDelaySeconds: 5 timeoutSeconds: 1 volumes: - name: data persistentVolumeClaim: claimName: postsql-data --- apiVersion: v1 kind: Service metadata: name: postgresql namespace: gitlab labels: name: postgresql spec: ports: - name: postgres port: 5432 targetPort: postgres selector: name: postgresql
然后执行如下命令创建Pod
kubectl apply -f postsql.yaml
vim redis.yaml apiVersion: v1 kind: Deployment metadata: namespace: gitlab name: redis lables: redis spec: selector: matchLabels: name: redis template: metadata: name: redis labels: name: redis spec: containers: - name: redis image: sameersbn/redis imagePullPolicy: IfNotPresent ports: - name: redis containerPort: 6379 volumeMounts: - mountPath: /var/lib/redis name: data livenessProbe: exec: command: - redis-cli - ping initialDelaySeconds: 30 timeoutSeconds: 5 readinessProbe: exec: command: - redis-cli - ping initialDelaySeconds: 5 timeoutSeconds: 1 volumes: - name: data persistentVolumeClaim: claimName: redis-data --- apiVersion: v1 kind: Service metadata: name: redis namespace: gitlab labels: name: redis spec: ports: - name: redis port: 6379 targetPort: redis selector: name: redis
然后执行如下命令即可创建
kubectl apply -f redis.yaml
vim gitlab.yaml apiVersion: v1 kind: Deployment metadata: namespace: gitlab name: gitlab lables: name: gitlab spec: selector: matchLabels: name: gitlab template: metadata: name: gitlab labels: name: gitlab spec: containers: - name: gitlab image: sameersbn/gitlab:11.8.1 imagePullPolicy: IfNotPresent env: - name: TZ value: Asia/Shanghai - name: GITLAB_TIMEZONE value: Beijing - name: GITLAB_SECRETS_DB_KEY_BASE value: long-and-random-alpha-numeric-string - name: GITLAB_SECRETS_SECRET_KEY_BASE value: long-and-RANDOM-ALPHA-NUMERIc-string - name: GITLAB_SECRETS_OTP_KEY_BASE value: long-and-random-alpha-numeric-string - name: GITLAB_ROOT_PASSWORD value: admin321 - name: GITLAB_ROOT_EMAIL value: hitredrose@163.com ##这里填自己的邮箱 - name: GITLAB_HOST value: 192.168.16.40 ##这里填gitlab的host地址,可以是主节点的ip - name: GITLAB_PORT value: "32765" # 与下面Service中配置的nodePort一致 - name: GITLAB_SSH_PORT # 与下面Service中配置的nodePort一致 value: "32766" - name: GITLAB_NOTIFY_ON_BROKEN_BUILDS value: "true" - name: GITLAB_NOTIFY_PUSHER value: "false" - name: GITLAB_BACKUP_SCHEDULE value: daily - name: GITLAB_BACKUP_TIME value: 01:00 - name: DB_TYPE value: postgres - name: DB_HOST value: postgresql - name: DB_PORT value: "5432" - name: DB_USER value: gitlab - name: DB_PASS value: gitlab - name: DB_NAME value: gitlab_production - name: REDIS_HOST value: redis - name: REDIS_PORT value: "6379" ports: - name: http containerPort: 80 - name: ssh containerPort: 22 volumeMounts: - mountPath: /home/git/data name: data livenessProbe: httpGet: path: / port: 80 initialDelaySeconds: 360 #这个值可以设置大一点,gitlab在启动时比较慢会处于一段时间的502,如果探测时间超过会进行重启,这样gitlab会一直处于重启状态 timeoutSeconds: 50 readinessProbe: httpGet: path: / port: 80 initialDelaySeconds: 360 timeoutSeconds: 50 volumes: - name: data persistentVolumeClaim: claimName: gitlab-data --- apiVersion: v1 kind: Service metadata: name: gitlab namespace: gitlab labels: name: gitlab spec: ports: - name: http port: 80 targetPort: http nodePort: 32765 - name: ssh port: 22 nodePort: 32766 targetPort: ssh selector: name: gitlab type: NodePort
然后执行如下命令创建gitlab
kubectl apply -f gitlab.yaml
[root@master gitlab]# kubectl get pod -n gitlab
NAME READY STATUS RESTARTS AGE
gitlab-855b5b7b7b-8hr97 1/1 Running 0 23m
postgresql-b75d769dd-dn2pt 1/1 Running 0 17h
redis-6c976f56dc-z7fsb 1/1 Running 0 55m
[root@master gitlab]#
然后通过Kubernetesmaster节点的ip地址和设置的端口比如这里32765,就可以访问gitlab了。
然后使用gitlab中设置的管理员密码,比如这里admin321,用户名root,就可以登录了,如下所示,为一个全新的gitlab。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。