文章目录
- K8s上安装gitlab-ce
- 操作如下
- gitlab-deployment.yml
K8s上安装gitlab-ce
前言
使用pv-pvc来持久化gitlab的数据,配置,日志文件。
pod启动后需要需要修改external_url然后重启pod。
操作如下
mkdir -p /mnt/data01/gitlab
ctr -n k8s.io i pull docker.io/gitlab/gitlab-ce:latest
kubectl label node [node_name] app=devops
kubectl apply -f gitlab-deployment.yml
如果镜像拉取不下来,可以
wget -c http://117.72.10.233/file/gitlab-ce.tgz
ctr -n k8s.io i import gitlab-ce.tgz
Pod起来之后,修改 /mnt/data01/gitlab/conf/gitlab.rb 文件,如下图所示修改,然后
kubectl get pods -n devops
kubectl delete pod [上面的gitlab的podname] -n devops
最后浏览器访问ip:30080即可访问gitlab,账号是root,密码是初始密码执行grep 'Password' /mnt/data01/gitlab/conf/initial_root_password
gitlab-deployment.yml
apiVersion: v1
kind: Namespace
metadata:name: devops
---
apiVersion: v1
kind: PersistentVolume
metadata:name: gitlab-pv-data
spec:accessModes:- ReadWriteOncecapacity:storage: 30GistorageClassName: gitlab-datahostPath:path: /mnt/data01/gitlab/data
---
apiVersion: v1
kind: PersistentVolume
metadata:name: gitlab-pv-conf
spec:accessModes:- ReadWriteOncecapacity:storage: 2GistorageClassName: gitlab-confhostPath:path: /mnt/data01/gitlab/conf
---
apiVersion: v1
kind: PersistentVolume
metadata:name: gitlab-pv-logs
spec:accessModes:- ReadWriteOncecapacity:storage: 10GistorageClassName: gitlab-logshostPath:path: /mnt/data01/gitlab/logs
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: gitlab-pvc-datanamespace: devops
spec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gilimits:storage: 30GistorageClassName: gitlab-data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: gitlab-pvc-confnamespace: devops
spec:accessModes:- ReadWriteOnceresources:requests:storage: 100Milimits:storage: 2GistorageClassName: gitlab-conf
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: gitlab-pvc-logsnamespace: devops
spec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gilimits:storage: 10GistorageClassName: gitlab-logs
---
apiVersion: apps/v1
kind: Deployment
metadata:name: gitlab-deploymentnamespace: devops
spec:replicas: 1selector:matchLabels:app: gitlab-cetemplate:metadata:labels:app: gitlab-cespec:nodeSelector:app: devopscontainers:- name: gitlab-ceimage: docker.io/gitlab/gitlab-ce:latestimagePullPolicy: IfNotPresentvolumeMounts:- name: datamountPath: /var/opt/gitlab- name: confmountPath: /etc/gitlab- name: logsmountPath: /var/log/gitlab- name: localtimemountPath: /etc/localtimevolumes:- name: datapersistentVolumeClaim:claimName: gitlab-pvc-data- name: confpersistentVolumeClaim:claimName: gitlab-pvc-conf- name: logspersistentVolumeClaim:claimName: gitlab-pvc-logs- name: localtimehostPath:path: /etc/localtime
---
apiVersion: v1
kind: Service
metadata:name: gitlab-svcnamespace: devops
spec:ports:- name: httpport: 80targetPort: 80nodePort: 30080- name: httpsport: 443targetPort: 443nodePort: 30443- name: sshport: 22targetPort: 22nodePort: 30022type: NodePortselector:app: gitlab-ce