5.《DevOps》系列K8S部署CICD流水线之K8S通过Yaml部署GitLab
架构
服务器IP | 服务名称 | 硬件配置 |
192.168.1.100 | k8s-master | 8核、16G、120G |
192.168.1.101 | k8s-node1 | 8核、16G、120G |
192.168.1.102 | k8s-node2 | 8核、16G、120G |
192.168.1.103 | nfs | 2核、4G、500G |
操作系统:Rocky9.3
后续通过K8S部署Jenkins
NFS的SC创建参考:2.《DevOps》系列K8S部署CICD流水线之部署NFS网络存储与K8S创建StorageClass-CSDN博客
此时部署GitLab需要先部署Redis、PostgreSQL
如果部署后拉取镜像失败,可以找个有docker的机器,拉取相关镜像,然后上传到K8S的两个node节点
#有docker的机器操作
docker pull redis:latest
docker pull sameersbn/postgresql:latest
docker pull sameersbn/gitlab:latest
docker save -o redis.tar redis:latest
docker save -o postgresql.tar sameersbn/postgresql:latest
docker save -o gitlab.tar sameersbn/gitlab:latest
#上传tar包到两个k8s节点进行操作
ctr -n k8s.io image import redis.tar redis:latest
ctr -n k8s.io image import postgresql.tar sameersbn/postgresql:latest
ctr -n k8s.io image import gitlab.tar sameersbn/gitlab:latest
部署Redis
#创建目录
mkdir -p /home/k8s/gitlab
cd /home/k8s/gitlab
vim gitlab_redis_dp_svc_pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-pvc
namespace: devops
spec:
accessModes:
- ReadWriteMany
storageClassName: "nfs-client" #写入之前部署好的SC名称
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: devops
labels:
name: redis
spec:
replicas: 1
selector:
matchLabels:
name: redis
template:
metadata:
name: redis
labels:
name: redis
spec:
containers:
- name: redis
image: redis:latest
imagePullPolicy: IfNotPresent
po