个人门户网站备案,电子会员卡系统哪个好,商城建设,免费网站建站教程K8S GitLab Jenkins自动化发布项目实践#xff08;一#xff09;发布流程设计安装Docker服务部署Harbor作为镜像仓库部署GitLab作为代码仓库常用Git命令发布流程设计 #mermaid-svg-pe9VmFytb9GmqMvG {font-family:trebuchet ms,verdana,arial,sans-serif;font-…
K8S GitLab Jenkins自动化发布项目实践一发布流程设计安装Docker服务部署Harbor作为镜像仓库部署GitLab作为代码仓库常用Git命令发布流程设计
#mermaid-svg-pe9VmFytb9GmqMvG {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-pe9VmFytb9GmqMvG .error-icon{fill:#552222;}#mermaid-svg-pe9VmFytb9GmqMvG .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-pe9VmFytb9GmqMvG .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-pe9VmFytb9GmqMvG .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-pe9VmFytb9GmqMvG .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-pe9VmFytb9GmqMvG .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-pe9VmFytb9GmqMvG .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-pe9VmFytb9GmqMvG .marker{fill:#333333;stroke:#333333;}#mermaid-svg-pe9VmFytb9GmqMvG .marker.cross{stroke:#333333;}#mermaid-svg-pe9VmFytb9GmqMvG svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-pe9VmFytb9GmqMvG .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-pe9VmFytb9GmqMvG .cluster-label text{fill:#333;}#mermaid-svg-pe9VmFytb9GmqMvG .cluster-label span{color:#333;}#mermaid-svg-pe9VmFytb9GmqMvG .label text,#mermaid-svg-pe9VmFytb9GmqMvG span{fill:#333;color:#333;}#mermaid-svg-pe9VmFytb9GmqMvG .node rect,#mermaid-svg-pe9VmFytb9GmqMvG .node circle,#mermaid-svg-pe9VmFytb9GmqMvG .node ellipse,#mermaid-svg-pe9VmFytb9GmqMvG .node polygon,#mermaid-svg-pe9VmFytb9GmqMvG .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-pe9VmFytb9GmqMvG .node .label{text-align:center;}#mermaid-svg-pe9VmFytb9GmqMvG .node.clickable{cursor:pointer;}#mermaid-svg-pe9VmFytb9GmqMvG .arrowheadPath{fill:#333333;}#mermaid-svg-pe9VmFytb9GmqMvG .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-pe9VmFytb9GmqMvG .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-pe9VmFytb9GmqMvG .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-pe9VmFytb9GmqMvG .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-pe9VmFytb9GmqMvG .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-pe9VmFytb9GmqMvG .cluster text{fill:#333;}#mermaid-svg-pe9VmFytb9GmqMvG .cluster span{color:#333;}#mermaid-svg-pe9VmFytb9GmqMvG div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-pe9VmFytb9GmqMvG :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}JenkinsGitdocker pulldocker pulldocker pushdocker buildUnit Testinggit checkoutgit commit测试工程师管理员互联网用户容器镜像Harbor测试环境生产环境kubectl APILoad Balance由于之前部署的k8s集群已经升级到v1.24容器运行时已经修改为containerd这里我们单独准备一台服务器用于部署Harbor和GitLab。需要安装docker服务。
安装Docker服务
systemctl stop firewalld
systemctl disable firewalld
sed -i s/enforcing/disabled/ /etc/selinux/config# 安装docker
yum install -y wget
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-18.06.1.ce-3.el7
systemctl enable docker systemctl start docker
docker --version配置国内容器镜像仓库
cat /etc/docker/daemon.json EOF
{registry-mirrors: [https://b9pmyelo.mirror.aliyuncs.com,http://hub-mirror.c.163.com/],insecure-registries: [https://b9pmyelo.mirror.aliyuncs.com],exec-opts: [native.cgroupdriversystemd]
}
EOF# 重启docker服务
systemctl restart docker部署Harbor作为镜像仓库
本小节我们使用docker-compose来部署Harbor作为镜像仓库。 ⛵️Harbor离线安装包下载地址https://github.com/goharbor/harbor/releases ⛵️Harbor部署配置https://goharbor.io/docs/2.7.0/install-config/ ⛵️docker-compose安装包下载https://github.com/docker/compose/releases/ 准备工作
mkdir /opt/harbor cd /opt/harbor
mv /root/harbor-offline-installer-v2.5.6.tgz /opt/harbor
tar zxvf harbor-offline-installer-v2.5.6.tgz
cd harbor
cp harbor.yml.tmpl harbor.yml
vi harbor.yml
# -配置hostname为指定IP或者FQDN
# -配置admin用户密码harbor_admin_password
# -先注释https相关配置生产环境不推荐# 安装docker-compose
cp /root/docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod x /usr/local/bin/docker-compose
docker-compose version部署本地Harbor
# 部署Harbor
cd /opt/harbor/harbor
./prepare # 会生成一个docker-compose.yml
./install.sh # 启动Harbor
docker-compose up -d
# 停止Harbor
docker-compose down -v部署完检查
# 需要在docker-compose.yml文件同级目录下执行
[rootharborgit harbor]# docker-compose psName Command State Ports
-----------------------------------------------------------------------------------------------------------------
harbor-core /harbor/entrypoint.sh Up (health: starting)
harbor-db /docker-entrypoint.sh 96 13 Up (health: starting)
harbor-jobservice /harbor/entrypoint.sh Up (health: starting)
harbor-log /bin/sh -c /usr/local/bin/ ... Up (health: starting) 127.0.0.1:1514-10514/tcp
harbor-portal nginx -g daemon off; Up (health: starting)
nginx nginx -g daemon off; Up (health: starting) 0.0.0.0:80-8080/tcp,:::80-8080/tcp
redis redis-server /etc/redis.conf Up (health: starting)
registry /home/harbor/entrypoint.sh Up (health: starting)
registryctl /home/harbor/start.sh Up (health: starting)部署完成后可以直接浏览器访问上面配置的hostname打开Harbor前端页面使用admin用户登录。 部署GitLab作为代码仓库 ⭐️官方地址https://about.gitlab.com/install/#official-linux-package 使用docker部署GitLab
mkdir /opt/gitlab
echo export GITLAB_HOME/opt/gitlab /root/.bash_profile
source /root/.bash_profile# 容器部署giltab镜像名称放到最后
docker run --detach --hostname gitlab.demo.com \--publish 443:443 --publish 88:80 --publish 2222:22 \--name gitlab --restart always \--volume $GITLAB_HOME/config:/etc/gitlab \--volume $GITLAB_HOME/logs:/var/log/gitlab \--volume $GITLAB_HOME/data:/var/opt/gitlab \gitlab/gitlab-ce取决于镜像拉取的速度部署完成大概需要3到5分钟。检查部署状态
[rootharborgit harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0795ec3b34e gitlab/gitlab-ce /assets/wrapper 5 minutes ago Up 5 minutes (healthy) 0.0.0.0:443-443/tcp, 0.0.0.0:2222-22/tcp, 0.0.0.0:88-80/tcp gitlab
3fa9ce8ec05d goharbor/nginx-photon:v2.5.6 nginx -g daemon of… 14 minutes ago Up 14 minutes (healthy) 0.0.0.0:80-8080/tcp nginx
07f156592a2f goharbor/harbor-jobservice:v2.5.6 /harbor/entrypoint.… 14 minutes ago Up 14 minutes (healthy) harbor-jobservice
3cfdec233a2c goharbor/harbor-core:v2.5.6 /harbor/entrypoint.… 14 minutes ago Up 14 minutes (healthy) harbor-core
b3ae94a48b85 goharbor/harbor-registryctl:v2.5.6 /home/harbor/start.… 15 minutes ago Up 14 minutes (healthy) registryctl
00e7fc671a26 goharbor/registry-photon:v2.5.6 /home/harbor/entryp… 15 minutes ago Up 14 minutes (healthy) registry
b84e56987d36 goharbor/harbor-db:v2.5.6 /docker-entrypoint.… 15 minutes ago Up 14 minutes (healthy) harbor-db
faf6f9d624cb goharbor/redis-photon:v2.5.6 redis-server /etc/r… 15 minutes ago Up 14 minutes (healthy) redis
f913b1c4c27c goharbor/harbor-portal:v2.5.6 nginx -g daemon of… 15 minutes ago Up 14 minutes (healthy) harbor-portal
f964a7a7492a goharbor/harbor-log:v2.5.6 /bin/sh -c /usr/loc… 15 minutes ago Up 15 minutes (healthy) 127.0.0.1:1514-10514/tcp harbor-log
部署完成后容器状态为healthy访问地址http://IP:88即可打开GitLab前端页面。初次登录需要设置root管理员用户密码。
获取管理员用户初始密码
docker logs gitlab容器ID | grep initial_root_password
cat /opt/gitlab/config/initial_root_password常用Git命令
# git全局设置
git config --global user.name admin
git config --global user.email adminexample.com# 创建一个新仓库
git clone gitgitlab.demos.com:root/java_demo.git
cd java_demo
touch README.md
git commit -m add README
git push -u origin master# 推送现有文件夹
cd existing_folder
git init
git remote add origin gitgitlab.demos.com:root/java_demo.git
git add .
git commit -m Initial commit
git push -u origin master# 推送现有Git仓库
cd existing_repo
git remote rename origin old-origin
git remote add origin gitgitlab.demos.com:root/java_demo.git
git push -u origin --all
git push -u origin --tags