k8s部署gitlab

1.环境准备

1.1 安装nfs
#所有机器安装
yum install -y nfs-utils
1.2 主节点
#nfs主节点
echo "/home/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports

mkdir -p /home/nfs/data
systemctl enable rpcbind --now
systemctl enable nfs-server --now
#配置生效
exportfs -r
1.3 从节点
showmount -e 192.168.150.201

#执行以下命令挂载 nfs 服务器上的共享目录到本机路径 /home/nfs/data
mkdir -p /home/nfs/data

mount -t nfs 192.168.150.201:/home/nfs/data /home/nfs/data
# 写入一个测试文件
echo "hello nfs server" > /home/nfs/data/test.txt
1.4 创建nfs共享目录
mkdir -p /home/nfs/data/gitlab/config
mkdir -p /home/nfs/data/gitlab/data
mkdir -p /home/nfs/data/gitlab/logs

2.部署gitlab

2.1 创建gitlab命名空间
apiVersion: v1
kind: Namespace
metadata:
  name: gitlab
2.2 创建pv持久卷
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv01-50gi
spec:
  capacity:
    storage: 50Gi
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-gitlab
  nfs:
    path: /home/nfs/data/gitlab/data
    server: 192.168.150.201
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv02-512mi
spec:
  capacity:
    storage: 512Mi
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-gitlab
  nfs:
    path: /home/nfs/data/gitlab/config
    server: 192.168.150.201
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv03-10gi
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-gitlab
  nfs:
    path: /home/nfs/data/gitlab/config
    server: 192.168.150.201

2.3 创建pvc持久卷声明
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: gitlab-data-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Gi
  storageClassName: nfs-gitlab
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: gitlab-config-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 512Mi
  storageClassName: nfs-gitlab
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: gitlab-logs-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: nfs-gitlab

2.4 部署gitlab应用
apiVersion: v1
kind: Service
metadata:
  name: gitlab
spec:
  type: NodePort
  ports:
  # Port上的映射端口
  - port: 443
    targetPort: 443
    name: gitlab443
  - port: 1680
    targetPort: 80
    name: gitlab80
  - port: 22
    targetPort: 22
    name: gitlab22
  selector:
    app: gitlab
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gitlab
spec:
  selector:
    matchLabels:
      app: gitlab
  template:
    metadata:
      labels:
        app: gitlab
    spec:
      containers:
      # 应用的镜像
      - image: gitlab/gitlab-ce 
        name: gitlab
        imagePullPolicy: IfNotPresent
        # 应用的内部端口
        ports:
        - containerPort: 443
          name: gitlab443
        - containerPort: 80
          name: gitlab80
        - containerPort: 22
          name: gitlab22
        volumeMounts:
        # gitlab持久化
        - name: gitlab-persistent-config
          mountPath: /etc/gitlab
        - name: gitlab-persistent-logs
          mountPath: /var/log/gitlab
        - name: gitlab-persistent-data
          mountPath: /var/opt/gitlab
      volumes:
      - name: gitlab-persistent-config
        persistentVolumeClaim:
          claimName: gitlab-config-pvc
      - name: gitlab-persistent-logs
        persistentVolumeClaim:
          claimName: gitlab-logs-pvc
      - name: gitlab-persistent-data
        persistentVolumeClaim:
          claimName: gitlab-data-pvc

pod信息:

2.5 访问初始界面

查看service暴露端口

kubectl get svc -A | grep gitlab

访问http://ip:30289

2.6 初始化密码

初始密码:用户名为root

cat /home/nfs/data/gitlab/config/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: moKJeWKEXSGykyfNcgUYrceVTyjxuA2B8QGVPP7Uans=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

修改密码:进入pod内部

gitlab-rake "gitlab:password:reset[root]"
Enter password: 
Confirm password: 
Password successfully updated for user with username root.

输入新密码

登陆后界面:

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐