装置长久化存储
# https://github.com/openebs/openebs/blob/main/translations/README.zh.md
kubectl apply -f https://openebs.github.io/charts/openebs-operator.yaml
# 查看集群的 StorageClass
kubectl get sc
# 将 openebs-hostpath 设置为 default
kubectl patch storageclass openebs-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
创立命名空间
kubectl create namespace devops
部署 redis
-
创立 pvc
# 创立 redis-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: redis-pvc namespace: devops spec: accessModes: - ReadWriteOnce # 这里指定应用的 OpenEBS 的 sc storageClassName: openebs-hostpath resources: requests: storage: 5Gi
# 执行创立命令 kubectl apply -f redis-pvc.yaml # 查看刚刚创立的 pvc kubectl get pvc -n devops redis-pvc
-
创立 Deployment
# 创立 redis-deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: redis namespace: devops labels: name: redis spec: replicas: 1 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-pvc
# 执行创立命令 kubectl apply -f redis-deploy.yaml # 查看刚刚创立的 deployment kubectl get pod -n devops
-
创立 Service
# 创立 redis-svc.yaml 文件
apiVersion: v1 kind: Service metadata: name: redis-svc namespace: devops labels: name: redis-svc spec: ports: - name: redis port: 6379 targetPort: redis selector: name: redis
# 执行创立命令 kubectl apply -f redis-svc.yaml # 查看刚刚创立的 svc kubectl get svc -n devops
部署 PG
-
创立 pvc
# 创立 pg-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgresql-pvc namespace: devops spec: accessModes: - ReadWriteOnce # 这里指定应用的 OpenEBS 的 sc storageClassName: openebs-hostpath resources: requests: storage: 5Gi
# 执行创立命令 kubectl apply -f pg-pvc.yaml # 查看刚刚创立的 svc kubectl get pvc -n devops
-
创立 Deployment
# 创立 pg-deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: postgresql namespace: devops labels: name: postgresql spec: replicas: 1 selector: matchLabels: name: postgresql template: metadata: name: postgresql labels: name: postgresql spec: containers: - name: postgresql image: sameersbn/postgresql:10 imagePullPolicy: IfNotPresent env: - name: DB_USER value: gitlab - name: DB_PASS value: passw0rd - 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: postgresql-pvc
# 执行创立命令 kubectl apply -f pg-deploy.yaml # 查看刚刚创立的 deployment kubectl get pod -n devops
-
创立 Service
# 创立 pg-svc.yaml
apiVersion: v1 kind: Service metadata: name: postgresql-svc namespace: devops labels: name: postgresql-svc spec: ports: - name: postgres port: 5432 targetPort: postgres selector: name: postgresql
# 执行创立命令 kubectl apply -f pg-svc.yaml # 查看刚刚创立的 deployment kubectl get svc -n devops
部署 Gitlab
-
创立 pvc
# 创立 gitlab-pvc.yaml 文件
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: gitlab-pvc namespace: devops spec: accessModes: - ReadWriteOnce storageClassName: openebs-hostpath resources: requests: storage: 5Gi
kubectl apply -f gitlab-pvc.yaml kubectl get pvc -n devops
-
创立 Deployment
apiVersion: apps/v1 kind: Deployment metadata: name: gitlab namespace: devops labels: name: gitlab spec: replicas: 1 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: [email protected] - name: GITLAB_HOST value: 10.111.127.141 - name: GITLAB_PORT value: "30180" - name: GITLAB_SSH_PORT value: "30022" - 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: passw0rd - 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: 180 timeoutSeconds: 5 readinessProbe: httpGet: path: / port: 80 initialDelaySeconds: 5 timeoutSeconds: 1 volumes: - name: data persistentVolumeClaim: claimName: gitlab-pvc
kubectl apply -f gitlab-deployment.yaml kubectl get pod -n devops
-
创立 Service
apiVersion: v1 kind: Service metadata: name: gitlab namespace: devops labels: name: gitlab spec: ports: - name: http port: 80 targetPort: http nodePort: 30180 - name: ssh port: 22 targetPort: ssh nodePort: 30022 selector: name: gitlab type: NodePort
kubectl apply -f gitlab-svc.yaml kubectl get svc -n devops