k8s部署gitlab并初始化和登录
准备环境
创建nfs共享目录
在nfs服务器创建共享目录,部署的gitlib使用共享目录来进行持久化,这样不管在哪个节点运行gitlib都没有关系
mkdir -p /data/nfs_data/gitlab/{logs,etc,opt}
添加到共享
[root@k8s-node2 nfs_data]# cat /etc/exports
/data/nfs_data 192.168.111.0/24(rw,sync,no_subtree_check,no_root_squash)
刷新一下配置
执行exportfs -rv
命令,nfs会重新读取配置文件,无需重启nfs服务
部署Gitlab
准备部署文件(gitlib-deploy.yaml)
apiVersion: v1
kind: Namespace
metadata:
name: devops-tools
---
apiVersion: v1
kind: Service
metadata:
name: gitlab-svc
namespace: devops-tools
spec:
selector:
app: gitlab-ce
type: NodePort
ports:
# - port: 443
# targetPort: 443
# nodePort: 32443
# name: https
- port: 80
targetPort: 80
nodePort: 32180
name: http
- port: 22
targetPort: 22
nodePort: 31122
name: ssh
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab-ce
namespace: devops-tools
spec:
selector:
matchLabels:
app: gitlab-ce
revisionHistoryLimit: 2
template:
metadata:
labels:
app: gitlab-ce
spec:
containers:
- image: gitlab-ce:15.8.3-ce.0
name: gitlab-ce
imagePullPolicy: IfNotPresent
ports:
- containerPort: 443
name: https
- containerPort: 80
name: http
- containerPort: 22
name: ssh
volumeMounts:
- name: gitlab-persistent-etc
mountPath: /etc/gitlab
- name: gitlab-persistent-logs
mountPath: /var/log/gitlab
- name: gitlab-persistent-opt
mountPath: /var/opt/gitlab
volumes:
- name: gitlab-persistent-etc
nfs:
server: 192.168.111.154
path: /data/nfs_data/gitlab/etc
- name: gitlab-persistent-logs
nfs:
server: 192.168.111.154
path: /data/nfs_data/gitlab/logs
- name: gitlab-persistent-opt
nfs:
server: 192.168.111.154
path: /data/nfs_data/gitlab/opt
nodeSelector:
kubernetes.io/hostname: k8s-node2 # 我指定到某个节点
还可以使用
pv/pvc
的方式去绑定部署volumes
执行部署
kubectl apply -f gitlib-deploy.yaml
查看部署结果
[root@k8s-master1 tmp]# kubectl get deploy -n devops-tools
NAME READY UP-TO-DATE AVAILABLE AGE
gitlab-ce 1/1 1 1 2d
以上说明部署完成
Gitlib初始化
访问登录页面
通过查看service映射的端口:
[root@k8s-master1 tmp]# kubectl get svc -n devops-tools
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
gitlab-svc NodePort 10.108.166.60 <none> 80:32180/TCP,22:31122/TCP 2d
可以看到映射80端口的节点端口为:32180
初始用户名和密码
首次登录,初始用户名为root,初始密码gitlib自动创建,在如下文件中:/etc/gitlab/initial_root_password
,但已经映射到nfs指定目录下,如此次映射的etc目录是/data/nfs_data/gitlab/etc
end,剩下就可以开始各种测试部署了。