记录一下在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

相关推荐
桦说编程1 天前
从 ForkJoinPool 的 Compensate 看并发框架的线程补偿思想
java·后端·源码阅读
蝎子莱莱爱打怪1 天前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
躺平大鹅1 天前
Java面向对象入门(类与对象,新手秒懂)
java
初次攀爬者1 天前
RocketMQ在Spring Boot上的基础使用
java·spring boot·rocketmq
花花无缺1 天前
搞懂@Autowired 与@Resuorce
java·spring boot·后端
Derek_Smart1 天前
从一次 OOM 事故说起:打造生产级的 JVM 健康检查组件
java·jvm·spring boot
NE_STOP1 天前
MyBatis-mybatis入门与增删改查
java
孟陬1 天前
国外技术周刊 #1:Paul Graham 重新分享最受欢迎的文章《创作者的品味》、本周被划线最多 YouTube《如何在 19 分钟内学会 AI》、为何我不
java·前端·后端
想用offer打牌1 天前
一站式了解四种限流算法
java·后端·go