rpm方式
源地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
vim /etc/gitlab.rb # 编辑站点地址
gitlab-ctl reconfigure # 配置
#服务控制
gitlab-ctl start
gitlab-ctl status
gitlab-ctl stop
Docker方式
mkdir -p ~/data/gitlab/config ~/data/gitlab/logs ~/data/gitlab/data
docker pull gitlab/gitlab-ce:12.9.0-ce.0
docker run -d -p 443:443 -p 80:80 -p 222:22 --name gitlab --restart always -v /Users/zeyang/data/gitlab/config:/etc/gitlab -v /Users/zeyang/data/gitlab/logs:/var/log/gitlab -v /Users/zeyang/data/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:12.9.0-ce.0
docker exec -it gitlab bash
vim /etc/gitlab.rb # 编辑站点地址
gitlab-ctl reconfigure # 配置
docker restart gitlab
#服务控制
docker start gitlab
docker stop gitlab
docker rm gitlab
Kubernetes部署
文件地址: https://github.com/zeyangli/devops-on-k8s/blob/master/devops/gitlab.yaml
---
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
k8s-app: gitlab
name: gitlab
namespace: devops
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: gitlab
template:
metadata:
labels:
k8s-app: gitlab
namespace: devops
name: gitlab
spec:
containers:
- name: gitlab
image: gitlab/gitlab-ce:12.6.0-ce.0
imagePullPolicy: Always
ports:
- containerPort: 30088
name: web
protocol: TCP
- containerPort: 22
name: agent
protocol: TCP
resources:
limits:
cpu: 1000m
memory: 4Gi
requests:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /users/sign_in
port: 30088
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
readinessProbe:
httpGet:
path: /users/sign_in
port: 30088
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
volumeMounts:
- name: gitlab-conf
mountPath: /etc/gitlab
- name: gitlab-log
mountPath: /var/log/gitlab
- name: gitlab-data
mountPath: /var/opt/gitlab
env:
- name: gitlab_HOME
value: /var/lib/gitlab
volumes:
- name: gitlab-conf
hostPath:
path: /data/devops/gitlab/config
type: Directory
- name: gitlab-log
hostPath:
path: /data/devops/gitlab/logs
type: Directory
- name: gitlab-data
hostPath:
path: /data/devops/gitlab/data
type: Directory
serviceAccountName: gitlab
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: gitlab
name: gitlab
namespace: devops
---
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: gitlab
name: gitlab
namespace: devops
spec:
type: NodePort
ports:
- name: web
port: 30088
targetPort: 30088
nodePort: 30088
- name: slave
port: 22
targetPort: 22
nodePort: 30022
selector:
k8s-app: gitlab
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: gitlab
namespace: devops
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get","list","watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: gitlab
namespace: devops
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: gitlab
subjects:
- kind: ServiceAccount
name: gitlab
namespace: devops
kubectl create -f gitlab.yaml
kubectl delete -f gitlab.yaml
注意: 需要修改gitlab.rb配置文件中的站点地址。这里指定的端口是30088(不是必须的)也就是需要将gitlab.rb配置的地址改成30088和nodePort端口为30088。
为什么端口要改成一致的?如果不修改gitlab.rb中的站点地址则默认是80端口,这时候做nodePort的时候例如将80映射到30088,此时对外访问30088可以打开gitlab页面,但是下载代码的时候会发现地址为80端口,导致下载代码失败。所以这里强调一致哦。
external-url-for-gitlab
external_url 'http://192.168.1.200:30088'