记录一下在k3s快速创建gitlab

废话不多说,直接上配置文件

需要修改的地方(备注都有写):

1.命名空间 namespace

  1. claimName 文件挂载

Deployment

复制代码
kind: Deployment
apiVersion: apps/v1
metadata:
  name: gitlab
  namespace: cicd  # 替换为您的命名空间
  labels:
    k8s.kuboard.cn/layer: svc
    k8s.kuboard.cn/name: gitlab
  annotations: {}
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s.kuboard.cn/layer: svc
      k8s.kuboard.cn/name: gitlab
  template:
    metadata:
      creationTimestamp: null
      labels:
        k8s.kuboard.cn/layer: svc
        k8s.kuboard.cn/name: gitlab
      annotations:
        kubectl.kubernetes.io/restartedAt: '2025-01-16T09:08:15+08:00'
    spec:
      volumes:
        - name: gitlab-data
          persistentVolumeClaim:
            claimName: gitlab-pvc  # 替换为您的 PVC 名称
      containers:
        - name: gitlab
          image: 'gitlab/gitlab-ce:14.3.5-ce.0'
          envFrom:
            - configMapRef:
                name: gitlab-env
          env:
            - name: TZ
              value: Asia/Shanghai
            - name: GITLAB_OMNIBUS_CONFIG
              valueFrom:
                configMapKeyRef:
                  name: gitlab-env
                  key: gitlab-config
          resources: {}
          volumeMounts:
            - name: gitlab-data
              mountPath: /var/opt/gitlab
              subPath: data/gitlab/data
            - name: gitlab-data
              mountPath: /var/log/gitlab
              subPath: data/gitlab/logs
            - name: gitlab-data
              mountPath: /etc/gitlab
              subPath: data/gitlab/config
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

注意:gitlab/gitlab-ce:14.3.5-ce.0 其中的版本,如果更换可以不可以没试过哈。

Service

复制代码
kind: Service
apiVersion: v1
metadata:
  name: gitlab
  namespace: cicd  # 替换为您的命名空间
  labels:
    k8s.kuboard.cn/layer: svc
    k8s.kuboard.cn/name: gitlab
spec:
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30009  # 根据需要调整
    - name: https
      protocol: TCP
      port: 443
      targetPort: 443
      nodePort: 30718  # 根据需要调整
    - name: ssh
      protocol: TCP
      port: 22
      targetPort: 22
      nodePort: 30256  # 根据需要调整
  selector:
    k8s.kuboard.cn/layer: svc
    k8s.kuboard.cn/name: gitlab
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster

ConfigMap

复制代码
kind: ConfigMap
apiVersion: v1
metadata:
  name: gitlab-env
  namespace: cicd  # 替换为您的命名空间
data:
  gitlab-config: |-
    external_url 'http://gitlab.yourdomain.com'  # 替换为您的 GitLab 外部访问地址
    gitlab_rails['gitlab_shell_ssh_port'] = 2222

PersistentVolumeClaim 与 PersistentVolume

稍微给一个demo(可不用哈)

复制代码
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: gitlab-pvc  # PVC 名称
  namespace: cicd  # 替换为您的命名空间
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Gi  # 根据需求调整存储大小
  storageClassName: nfs-class  # 使用您的 NFS 存储类

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: nfs-nfs-class
  finalizers:
    - kubernetes.io/pv-protection
  name: gitlab-pv
  resourceVersion: '5781171'
spec:
  accessModes:
    - ReadWriteMany
  capacity:
    storage: 100Gi
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: gitlab-pvc
    namespace: cicd
  nfs:
    path: /k3s/gitlab
    server: 192.168.1.x
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs-class
  volumeMode: Filesystem

部署成功

查看密码(初始密码)

控制台输入命令

复制代码
cat /etc/gitlab/initial_root_password

密码就是上面的那一串位置。

修改密码


博主新推出 的gitee免费开源项目(商城+APP+小程序+H5),有兴趣的小伙伴可 以了解一下。

生鲜商城kxmall-小程序 + App + 公众号H5: kxmall-生鲜商城+APP+小程序+H5。同时支持微信小程序、H5、安卓App、苹果App。支持集群部署,单机部署。可用于B2C商城,O2O外卖,社区超市,生鲜【带配套骑手端配送系统】。kxmall使用uniapp编码。使用Java开发,SpringBoot 2.1.x框架,MyBatis-plus持久层框架、Redis作为缓存、MySql作为数据库。前端vuejs作为开发语言。https://gitee.com/zhengkaixing/kxmall

相关推荐
栗子~~37 分钟前
idea 安装飞算-javaAI 插件使用
java·ide·intellij-idea
zy happy2 小时前
黑马点评前端Nginx启动失败问题解决记录
java·运维·前端·spring boot·nginx·spring
lxyker2 小时前
MongoDB大数据量的优化——mongoTemplate.stream()方法使用
java·数据库·mongodb·性能优化·数据库调优
煤灰2422 小时前
简单用c++的类实现的string
java·开发语言·c++
vibag3 小时前
第十六届蓝桥杯复盘
java·算法·蓝桥杯·竞赛
珹洺3 小时前
计算机操作系统(十一)调度器/调度程序,闲逛调度与调度算法的评价指标
android·java·算法
墨着染霜华3 小时前
JAVA8怎么使用9的List.of
java·list
编程、小哥哥3 小时前
Java求职面经分享:Spring Boot到微服务,从理论到实践
java·hadoop·spring boot·微服务·kafka
有梦想的攻城狮4 小时前
spring中的BeanFactoryAware接口详解
java·后端·spring·beanfactory
若汝棋茗4 小时前
C#在 .NET 9.0 中启用二进制序列化:配置、风险与替代方案
java·c#·.net·序列化