文章目录
- 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 文件,修改配置然后重启Pod
cat >> /mnt/data01/gitlab/conf/gitlab.rb << 'eof'
external_url 'http://123.60.108.111:30080' ## ip需要修改为访问地址
gitlab_rails['gitlab_ssh_host'] = '123.60.108.111' ## ip需要修改为访问地址
gitlab_rails['gitlab_shell_ssh_port'] = 30022
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "1391578633@qq.com"
gitlab_rails['smtp_password'] = "yasfadsfafddfdj" ## 密码为qq的smtp授权码
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '1391578633@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['gitlab_email_reply_to'] = '1391578633@qq.com'
gitlab_rails['gitlab_email_subject_suffix'] = '[gitlab]'
eof
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
spec:accessModes:- ReadWriteOncecapacity:storage: 50GistorageClassName: gitlab-cehostPath:path: /mnt/data01/gitlab
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: gitlab-pvcnamespace: devops
spec:accessModes:- ReadWriteOnceresources:requests:storage: 2Gilimits:storage: 50GistorageClassName: gitlab-ce
---
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: gen-dirmountPath: /var/opt/gitlabsubPath: data- name: gen-dirmountPath: /etc/gitlabsubPath: conf- name: gen-dirmountPath: /var/log/gitlabsubPath: logs- name: localtimemountPath: /etc/localtimevolumes:- name: gen-dirpersistentVolumeClaim:claimName: gitlab-pvc- name: localtimehostPath:path: /etc/localtime
---
apiVersion: v1
kind: Service
metadata:name: gitlab-svcnamespace: devops
spec:ports:- name: httpport: 30080targetPort: 30080nodePort: 30080- name: httpsport: 443targetPort: 443nodePort: 30443- name: sshport: 22targetPort: 22nodePort: 30022type: NodePortselector:app: gitlab-ce