一、安装docker环境
略.
二、下载离线安装包
下载地址
https://github.com/goharbor/harbor/releases/download/v1.10.15/harbor-offline-installer-v1.10.15.tgz三、拷贝到服务器/application
- #解压
- tar -xvf harbor-online-installer-v1.2.0.tgz
- #生成证书
- cd /application
- mkdir cert && cd cert
- openssl req -sha256 -x509 -days 365 -nodes -newkey rsa:4096 -keyout harbor.example.com.key -out harbor.example.com.crt
- #编辑配置文件
- nano /application/harbor/harbor.yml
- #############修改#############
- hostname: harbor.example.com
- certificate: /application/cert/harbor.example.com.crt
- private_key: /application/cert/harbor.example.com.key
- ##############################
-
- cd /application/harbor
- ./install.sh
访问:windowns 机器上配置host

登录: http://harobr.example.com
用户名:admin
密码:Harbor12345
四、上传镜像
设置Linux设置Host
- sed -i '$a 127.0.0.1 harbor.example.com' /etc/hosts
- nano /etc/docker/daemon.json
- ###########添加一段###########
- "insecure-registries":["192.168.31.105"]
- #############################
- #重启docker
- sudo systemctl daemon-reload
- sudo systemctl restart docker
例如现在已构建了一个镜像:netcore6.demo:v1.0.1 需要上传,则先执行
- docker tag netcore6.demo:v1.0.1 192.168.31.105/demos/netcore6.demo:v1.0.1
- #登录成功
- docker login 192.168.31.105 #admin Harbor12345
- #上传
- docker push 192.168.31.105/demos/netcore6.demo:v1.0.1

五、k8s拉取镜像部属
k8服务器上添加镜像库地址:
- sed -i '$a 192.168.31.105 harbor.example.com' /etc/hosts
-
- nano /etc/docker/daemon.json 添加一段:"insecure-registries":["harbor.example.com"]
- {
- "insecure-registries":["harbor.example.com"],
- "registry-mirrors": ["https://nlrpuctd.mirror.aliyuncs.com"],
-
- }
-
- systemctl restart docker
- kubectl create -f /root/k8sdeploy/netcore6.demo/api-demo-harbor-com-deployment.yaml
- kubectl create -f /root/k8sdeploy/netcore6.demo/api-demo-harbor-com-service.yaml
api-demo-harbor-com-deployment.yaml
- {
- "apiVersion": "apps/v1",
- "kind": "Deployment",
- "metadata": {
- "annotations": {},
- "name": "api-demo-harbor-com-deployment",
- "namespace": "default"
- },
- "spec": {
- "replicas": 1,
- "revisionHistoryLimit": 2,
- "selector": {
- "matchLabels": {
- "app": "api-demo-harbor-com"
- }
- },
- "template": {
- "metadata": {
- "labels": {
- "app": "api-demo-harbor-com"
- }
- },
- "spec": {
- "containers": [
- {
- "image": "harbor.example.com/demos/netcore6.demo:v1.0.1",
- "imagePullPolicy": "IfNotPresent",
- "name": "api-demo-harbor-com",
- "ports": [
- {
- "containerPort": 80
- }
- ],
- "resources": {
- "limits": {
- "cpu": "200m",
- "memory": "500Mi"
- },
- "requests": {
- "cpu": "200m",
- "memory": "100Mi"
- }
- },
- "volumeMounts": [
- {
- "mountPath": "/mnt/api.demo.harbor.com",
- "name": "data"
- },
- {
- "mountPath": "/mnt/cert",
- "name": "cert"
- }
- ]
- }
- ],
- "hostAliases": [
- {
- "hostnames": [
- "api.demo.harbor.com"
- ],
- "ip": "192.168.1.107"
- }
- ],
- "volumes": [
- {
- "hostPath": {
- "path": "/kubernetes/wwwroot/api.demo.harbor.com"
- },
- "name": "data"
- },
- {
- "hostPath": {
- "path": "/kubernetes/cert"
- },
- "name": "cert"
- }
- ]
- }
- }
- }
- }
api-demo-harbor-com-service.yaml
- {
- "apiVersion": "v1",
- "kind": "Service",
- "metadata": {
- "annotations": {},
- "labels": {
- "app": "api-demo-harbor-com"
- },
- "name": "api-demo-harbor-com",
- "namespace": "default"
- },
- "spec": {
- "ports": [
- {
- "port": 80,
- "nodePort": 32767,
- "protocol": "TCP",
- "targetPort": 80
- }
- ],
- "selector": {
- "app": "api-demo-harbor-com"
- },
- "type": "NodePort"
- }
- }


