K8S(三)——部署docker环境,配置Harbor仓库
在SX7-200,SX7-21,SX7-22主机上安装docker
一、以下在三台机器都配置
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
二、配置镜像加速器(三台)
mkdir /etc/docker
mkdir /data/docker -p
vim /etc/docker/daemon.json
{
"graph": "/data/docker",
"storage-driver": "overlay2",
"insecure-registries": ["registry.access.redhat.com","quay.io","harbor.xyly.com"], // harbor.xyly.com 为私有仓库的域名
"registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
"bip": "172.7.200.1/24", // SX7-21主机为172.7.21.1,SX7-22主机为172.7.22.1
"exec-opts": ["native.cgroupdriver=systemd"],
"live-restore": true
}
三、启动docker(三台)
systemctl enable --now docke
搭建私有Harbor仓库
一、下载harbor-offline-installer-v1.8.0.tgz
cd /opt
wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.0.tgz
tar -xf harbor-offline-installer-v1.8.0.tgz
mv harbor harbor-v1.8.0 // 重命名解压后的harbor
ln -s /opt/harbor-v1.8.0 /opt/harbor
二、配置harbor
mkdir -p /data/harbor/logs // 创建日志目录
vim harbor/harbor.yml // 不添加,修改如下:
hostname: harbor.xyly.com
http:
port: 180
harbor_admin_password: Harbor12345 // 登录的密码
log:
location: /data/harbor/logs
data_volume: /data/harbor
三、安装docker-compose
yum install -y docker-compose.noarch
四、安装harbor
sh /opt/harbor/install.sh
进入harbor目录再docker-compose ps,否则是报错的
五、安装nginx
yum install -y nginx
配置
vim /etc/nginx/conf.d/harbor.xyly.com.conf
server {
listen 80;
server_name harbor.xyly.com;
client_max_body_size 1000m;
location / {
proxy_pass http://127.0.0.1:180;
}
}
检查配置文件有无错误
systemctl enable --now nginx
如果nginx启动报错,参考解决方法https://www.cnblogs.com/xyly/p/12902173.html
六、在SX7-11主机上配置上述haror的dns
vim /var/named/xyly.com.zone // 添加一条A记录
harbor A 10.4.7.200
systemctl restart named
测试
七、浏览器访问harbor.xyly.com,访问502错误的话重启docker,再重启nginx试试
进入后
第一、点击新建项目
第二,拉取镜像
docker pull nginx:1.7.9
查看拉取的镜像
第三、将镜像上传至私有Harbor仓库
docker tag 84581e99d807 harbor.xyly.com/public/nginx:v1.7.9 // 给下载的镜像打个标记
登录私有仓库
上传镜像
docker push harbor.xyly.com/public/nginx:v1.7.9