文章目录
- 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:
- ReadWriteOnce
capacity:
storage: 30Gi
storageClassName: gitlab-data
hostPath:
path: /mnt/data01/gitlab/data
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: gitlab-pv-conf
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 2Gi
storageClassName: gitlab-conf
hostPath:
path: /mnt/data01/gitlab/conf
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: gitlab-pv-logs
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
storageClassName: gitlab-logs
hostPath:
path: /mnt/data01/gitlab/logs
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gitlab-pvc-data
namespace: devops
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
limits:
storage: 30Gi
storageClassName: gitlab-data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gitlab-pvc-conf
namespace: devops
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
limits:
storage: 2Gi
storageClassName: gitlab-conf
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gitlab-pvc-logs
namespace: devops
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
limits:
storage: 10Gi
storageClassName: gitlab-logs
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab-deployment
namespace: devops
spec:
replicas: 1
selector:
matchLabels:
app: gitlab-ce
template:
metadata:
labels:
app: gitlab-ce
spec:
nodeSelector:
app: devops
containers:
- name: gitlab-ce
image: docker.io/gitlab/gitlab-ce:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- name: data
mountPath: /var/opt/gitlab
- name: conf
mountPath: /etc/gitlab
- name: logs
mountPath: /var/log/gitlab
- name: localtime
mountPath: /etc/localtime
volumes:
- name: data
persistentVolumeClaim:
claimName: gitlab-pvc-data
- name: conf
persistentVolumeClaim:
claimName: gitlab-pvc-conf
- name: logs
persistentVolumeClaim:
claimName: gitlab-pvc-logs
- name: localtime
hostPath:
path: /etc/localtime
---
apiVersion: v1
kind: Service
metadata:
name: gitlab-svc
namespace: devops
spec:
ports:
- name: http
port: 80
targetPort: 80
nodePort: 30080
- name: https
port: 443
targetPort: 443
nodePort: 30443
- name: ssh
port: 22
targetPort: 22
nodePort: 30022
type: NodePort
selector:
app: gitlab-ce