云原生之kubernetes实战在k8s集群下搭建gitlab
Posted 江湖有缘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了云原生之kubernetes实战在k8s集群下搭建gitlab相关的知识,希望对你有一定的参考价值。
【云原生之kubernetes实战】在k8s集群下搭建gitlab
- 一、gitlab介绍
- 二、检查本地k8s集群状态
- 三、安装nfs共享存储
- 四、创建本地挂载目录
- 五、部署gitlab
- 六、查看gitlab相关资源对象
- 七、查看gitlab登录账号密码
- 八、修改gitlab管理员密码
- 九、gitlab设置简体中文
一、gitlab介绍
1.gitlab简介
Gitlab是一个开源分布式版本控制系统,由Ruby开发,有管理项目源代码、版本控制、代码复用与查找等功能。
2.gitlab的特点
1. 开源免费,社区免费版本适合中小型公司;
2. 差异化的版本管理,离线同步以及强大分支管理功能;
3. 便捷的GUI操作界面以及强大账户权限管理功能;
4. 集成度很高,能够集成绝大多数的开发工具;
3.github和gitlab区别
github是分布式在线代码托管仓库,个人版本可直接在线免费使用,企业版本收费且需要服务器安装。
gitlab是分布式在线代码仓库托管软件,分社区免费版本与企业收费版本,都需要服务器安装。
二、检查本地k8s集群状态
[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
三、安装nfs共享存储
1.安装nfs
yum install -y nfs-utils
2.创建共享目录
mkdir -p /nfs/data
3.配置共享目录
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
4.使配置生效
exportfs -r
5.重启nfs相关服务
①设置nfs服务开机启动
systemctl enable --now rpcbind
systemctl enable --now nfs-server
②重启nfs服务
service rpcbind stop
service nfs stop
service rpcbind start
service nfs start
6.其他节点检查nfs共享
[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
五、部署gitlab
1.下载gitlab镜像
[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)
2.编写gitlab.yam文件
[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
3.应用gitlab.yaml文件
kubectl apply -f gitlab.yaml
六、查看gitlab相关资源对象
1.查看pod状态
[root@k8s-master gitlab]# kubectl get pod
NAME READY STATUS RESTARTS AGE
gitlab-7767cc976d-m4nq8 1/1 Running 0 21m
2.查看svc
[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
3.查看gitlab安装信息
[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!
七、查看gitlab登录账号密码
1.进入gitlab的容器内
[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:/#
2.查看gitlab密码
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.
八、修改gitlab管理员密码
1.登录gitlab
http://192.168.3.203:31232/users/sign_in
2.修改密码
九、gitlab设置简体中文
1.设置界面中文
2.查看中文效果
以上是关于云原生之kubernetes实战在k8s集群下搭建gitlab的主要内容,如果未能解决你的问题,请参考以下文章
云原生之kubernetes实战在k8s集群环境下部署Tomcat应用
云原生之kubernetes实战在k8s下部署Redis集群
云原生之kubernetes实战在k8s集群下部署Weave Scope监控平台
云原生之kubernetes实战在k8s集群下部署ingress对外访问服务