Gitlab是一个开源分布式版本控制系统,由Ruby开发,有管理项目源代码、版本控制、代码复用与查找等功能。
1. 开源免费,社区免费版本适合中小型公司;
2. 差异化的版本管理,离线同步以及强大分支管理功能;
3. 便捷的GUI操作界面以及强大账户权限管理功能;
4. 集成度很高,能够集成绝大多数的开发工具;
github是分布式在线代码托管仓库,个人版本可直接在线免费使用,企业版本收费且需要服务器安装。
gitlab是分布式在线代码仓库托管软件,分社区免费版本与企业收费版本,都需要服务器安装。
[root@k8s-master gitlab]# kubectl get nodes -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 4d16h v1.23.1 192.168.3.201 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node01 Ready <none> 4d16h v1.23.1 192.168.3.202 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node02 Ready <none> 4d16h v1.23.1 192.168.3.203 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
yum install -y nfs-utils
mkdir -p /nfs/data
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
exportfs -r
systemctl enable --now rpcbind
systemctl enable --now nfs-server
service rpcbind stop
service nfs stop
service rpcbind start
service nfs start
[root@k8s-node01 ~]# showmount -e 192.168.3.201
Export list for 192.168.3.201:
/nfs/data *
mkdir -p /nfs/data/gitlab/data
mkdir -p /nfs/data/gitlab/logs
mkdir -p /nfs/data/gitlab/config
[root@k8s-master gitlab]# nerdctl pull gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest: resolved |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:b40822d4f5e6ba47b5d82bce35689d02d77ecf8d286a9e394fc62306b03eeb05: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:0bd8093d0f9750cceb6629dab2f164f83e15500f9ac8a62323e938d7d6ee1e77: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:76ba78f867ece577e4f2689452f0a254d56c508edb1e91127282a4fac422e941: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:d7bfe07ed8476565a440c2113cc64d7c0409dba8ef761fb3ec019d7e6b5952df: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:c8ced22785510da03e153761ec78be766dbefa17463525263e6a37c7316a3bb0: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:d5b7cafbee00da1dcf0d3161f11b5ea3f48ea5e510ee903d643978bb1397aee3: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:379aa7e9779125f350483ad0bdc2250686501ddf7be6dc71d8d9211e4dc652b6: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:8459a3c7f805f3786684f1243fe9fd814ccc8c5a4a280d319adcbb0e5e0eb0c1: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:4562b6e1a5781116b34a70f0aa9007b5d95b84677d326f55cc81c92735b41930: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:11ebb50b10057d816ab159b9e2635b092ac0f90b6238dc029a77c8aef532c332: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 607.0s total: 1.1 Gi (1.8 MiB/s)
[root@k8s-master gitlab]# cat gitlab.yaml
apiVersion: v1
kind: Service
metadata:
name: gitlab
spec:
type: NodePort
ports:
# Port上的映射端口
- port: 443
targetPort: 443
name: gitlab443
- port: 80
targetPort: 80
name: gitlab80
nodePort: 31232
- port: 22
targetPort: 22
name: gitlab22
selector:
app: gitlab
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab
spec:
replicas: 1
selector:
matchLabels:
app: gitlab
revisionHistoryLimit: 2
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:
- name: gitlab-persistent-config
mountPath: /etc/gitlab
- name: gitlab-persistent-logs
mountPath: /var/log/gitlab
- name: gitlab-persistent-data
mountPath: /var/opt/gitlab
imagePullSecrets:
- name: devops-repo
volumes:
# 使用nfs存储
- name: gitlab-persistent-config
nfs:
server: 192.168.3.201
path: /nfs/data/gitlab/config
- name: gitlab-persistent-logs
nfs:
server: 192.168.3.201
path: /nfs/data/gitlab/logs
- name: gitlab-persistent-data
nfs:
server: 192.168.3.201
path: /nfs/data/gitlab/data
kubectl apply -f gitlab.yaml
[root@k8s-master gitlab]# kubectl get pod
NAME READY STATUS RESTARTS AGE
gitlab-7767cc976d-m4nq8 1/1 Running 0 21m
[root@k8s-master gitlab]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
gitlab NodePort 10.109.216.28 <none> 443:31462/TCP,80:31232/TCP,22:31674/TCP 22m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5d15h
[root@k8s-master gitlab]# kubectl logs gitlab-7767cc976d-m4nq8
Recipe: monitoring::alertmanager
* runit_service[alertmanager] action restart (up to date)
Recipe: monitoring::postgres-exporter
* runit_service[postgres-exporter] action restart (up to date)
Recipe: monitoring::grafana
* runit_service[grafana] action restart (up to date)
Running handlers:
Running handlers complete
Chef Infra Client finished, 509/1425 resources updated in 04 minutes 59 seconds
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
gitlab Reconfigured!
[root@k8s-master gitlab]# kubectl exec -it gitlab-7767cc976d-m4nq8 /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@gitlab-7767cc976d-m4nq8:/#
root@gitlab-7767cc976d-m4nq8:/# cat /etc/gitlab/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: yZpPrFKbJY9CSkFx4bquNchXkEuegxKrBOcW2IINg8E=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.