首先你需要先部署好k8s的集群
k8s集群安装:使用kubeadm来部署Kubernetes单节点,比二进制部署快多了!!
一、准备一台harbor服务器(192.168.73.155)
关闭防火墙和安全功能,修改主机名
systemctl stop firewalld
setenforce 0
hostnamectl set-hostname harbor
二、所有节点加上主机名映射
echo '192.168.73.155 hub.lwh.com' >> /etc/hosts
harbor服务器安装 docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
mkdir /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://6ijb8ubo.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"insecure-registries": ["https://hub.lwh.com"]
}
EOF
systemctl start docker
systemctl enable docker
三、安装 Harbor
上传 harbor-offline-installer-v1.2.2.tgz 和 docker-compose 文件到 /opt 目录
cd /opt
cp docker-compose /usr/local/bin/
chmod +x /usr/local/bin/docker-compose
tar zxvf harbor-offline-installer-v1.2.2.tgz
cd harbor/
vim harbor.cfg
5 hostname = hub.kgc.com
9 ui_url_protocol = https
24 ssl_cert = /data/cert/server.crt
25 ssl_cert_key = /data/cert/server.key
59 harbor_admin_password = Harbor12345
四、生成证书
mkdir -p /data/cert
cd /data/cert
#生成私钥
openssl genrsa -des3 -out server.key 2048
输入两遍密码:123456
五、生成证书签名请求文件
openssl req -new -key server.key -out server.csr
输入私钥密码:123456
输入国家名:CN
输入省名:BJ
输入市名:BJ
输入组织名:LWH
输入机构名:LWH
输入域名:hub.lwh.com
输入管理员邮箱:admin@lwh.com
其它全部直接回车
#备份私钥
cp server.key server.key.org
#清除私钥密码
openssl rsa -in server.key.org -out server.key
输入私钥密码:123456
#签名证书
openssl x509 -req -days 1000 -in server.csr -signkey server.key -out server.crt
chmod +x /data/cert/*
cd /opt/harbor/
./install.sh
六、浏览器访问测试
使用Linux自带的火狐浏览器
点击高级--添加例外--确定
https://hub.lwh.com
用户名:admin
密码:Harbor12345
在一个node节点上登录harbor
docker login -u admin -p Harbor12345 https://hub.lwh.com
上传镜像
docker tag nginx:latest hub.lwh.com/library/nginx:v1
docker push hub.lwh.com/library/nginx:v1
在master节点上删除之前创建的nginx资源
kubectl delete deployment nginx
kubectl run nginx-deployment --image=hub.lwh.com/library/nginx:v1 --port=80 --replicas=3
yum install ipvsadm -y
ipvsadm -Ln
curl 10.96.37.127:30000
把调度策略改成NodePort
kubectl edit svc nginx-deployment
25 type: NodePort
浏览器访问测试
http://192.168.73.66:30174/
http://192.168.73.168:30174/
http://192.168.73.55:30174/