构建gitlab+Jenkins+harbor+kubernetes的DevOps持续集成持续部署环

参考:https://blog.51cto.com/13231454/2447234

https://www.cnblogs.com/wangxu01/articles/11738284.html

整个环境的结构图:


节点名 ip地址 作用 安装中间件
hub.k8s.com 192.168.224.130 源码托管 Gitlab/Docker
镜像托管 Harbor/Docker
在线编译 Jenkins
包托管 Helm
k8s-master 192.168.224.131 容器编码Master K8s/Docker
k8s-node01 192.168.224.132 容器编码Node1 K8s/Docker
k8s-node02 192.168.224.133 容器编码Node2 K8s/Docker

1. gitlab部署

1.1 拉取镜像

docker pull gitlab/gitlab-ce

1.2. 启动gitlab

docker run --detach
--publish 10443:443 --publish 10080:80 --publish 10022:22
--name gitlab
--restart always
--volume /opt/gitlab/config:/etc/gitlab
--volume /opt/gitlab/logs:/var/log/gitlab
--volume /opt/gitlab/data:/var/opt/gitlab
gitlab/gitlab-ce:latest

vi /opt/gitlab/data/gitlab-rails/etc/gitlab.yml
docker commit -a "luds" -m "gitlab hostname port version" 75bf1dec29a3 hub.k8s.com/test/gitlab-ce:v1

2. git 部署

yum install git

3. jenkins

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins

tail -f /var/log/jenkins/jenkins.log
log中输出jenkins网页端初始化密码。

vim /etc/sysconfig/jenkins

监听端口

JENKINS_PORT="8080"

vim /etc/sysconfig/jenkins

修改配置

$JENKINS_USER="root"

给目录分配权限

chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins

重启jenkins服务

service jenkins restart
ps -ef | grep jenkins

systemctl start jenkins

如果浏览器访问不了,请确认防火墙端口是否打开

firewall-cmd --permanent --zone=public --add-port=8088/tcp
firewall-cmd --permanent --zone=public --add-port=10080/tcp

记得重新装载防火墙

systemctl reload firewalld

4. harbor

将下载的安装包解压到指定目录

tar zxf harbor-offline-installer-v1.7.4.tgz -C /usr/local/src

切换至解压后的目录中

cd /usr/local/src/harbor/
./install.sh

出错对应

Q:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
A:service docker start
Q:更改Gitlab的克隆地址
A:vim /opt/gitlab/data/gitlab-rails/etc/gitlab.yml
gitlab-ctl restart
ssh-keygen -t rsa -b 2048 -C "[email protected]"

你可能感兴趣的:(构建gitlab+Jenkins+harbor+kubernetes的DevOps持续集成持续部署环)