• 【云原生.大数据】镜像仓库Harbor对接MinIO对象存储


    一、前言

    Harbor的部署之前使用的存储是NFS,虽然可以使用rsync+inotify做数据同步做解决单点问题,但是NFS效率/性能有限,没有对象存储那么强大,所以一般使用对象存储居多,这里选用MinIO 对象存储软件,当然也可以使用Ceph或者其它对象存储。都部署在k8s 集群上,k8s 基础环境部署可以参考我之前的文章:Kubernetes(k8s)最新版最完整版环境部署+master高可用实现(k8sV1.24.1+dashboard+harbor)

    二、MinIO on K8S 部署

    在这里插入图片描述

    MinIO 的介绍可以参考我这篇文章:高性能分布式对象存储——MinIO(环境部署)

    这里使用Helm 部署 MinIO ,关于 Helm 的介绍可以参考官方文档,部署步骤如下:

    1)下载安装 MinIO 包

    mkdir -p /opt/k8s/bigdata/minio;cd /opt/k8s/bigdata/minio
    # 添加数据源
    helm repo add bitnami https://charts.bitnami.com/bitnami
    # 下载
    helm pull bitnami/minio
    # 解压部署包
    tar -xf minio-11.9.2.tgz
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    2)修改配置

    添加文件minio/templates/storage-class.yaml,内容如下:

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
      name: minio-local-storage
    provisioner: kubernetes.io/no-provisioner
    volumeBindingMode: WaitForFirstConsumer
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    添加 pv 配置 minio/templates/pv.yaml

    {{- range .Values.persistence.local }}
    ---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: {{ .name }}
    spec:
      capacity:
        storage: {{ .size }}
      accessModes:
      - ReadWriteOnce
      persistentVolumeReclaimPolicy: Retain
      storageClassName: minio-local-storage
      local:
        path: {{ .path }}
      nodeAffinity:
        required:
          nodeSelectorTerms:
          - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
              - {{ .host }}
     ---
    {{- end }}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    修改配置minio/values.yaml

    service:
      type: NodePort
      nodePorts:
        api: "30900"
        console: "30901"
    
    # ---
    # 这里先部署单节点,后面会详细讲在k8s中部署分布式minio,这里的重点是Harbor对接minio
    mode: standalone
    
    # ---
    statefulset:
      replicaCount: 4
    
    # ---
    persistence
      enabled: true
      storageClass: minio-local-storage
      size: 1Gi
      local:
        - name: minio-pv-0
          size: 1Gi
          path: /opt/k8s/bigdata/minio/data
          host: local-168-182-110
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    【温馨提示】需要提前在对应的节点上创建对应的目录。

    3)开始部署

    cd /opt/k8s/bigdata/minio
    helm install minio ./minio \
      --namespace=minio \
      --create-namespace
    
    • 1
    • 2
    • 3
    • 4

    notes

    NAME: minio
    LAST DEPLOYED: Sun Aug 28 09:13:06 2022
    NAMESPACE: minio
    STATUS: deployed
    REVISION: 1
    TEST SUITE: None
    NOTES:
    CHART NAME: minio
    CHART VERSION: 11.9.2
    APP VERSION: 2022.8.22
    
    ** Please be patient while the chart is being deployed **
    
    MinIO® can be accessed via port  on the following DNS name from within your cluster:
    
       minio.minio.svc.cluster.local
    
    To get your credentials run:
    
       export ROOT_USER=$(kubectl get secret --namespace minio minio -o jsonpath="{.data.root-user}" | base64 -d)
       export ROOT_PASSWORD=$(kubectl get secret --namespace minio minio -o jsonpath="{.data.root-password}" | base64 -d)
    
    To connect to your MinIO® server using a client:
    
    - Run a MinIO® Client pod and append the desired command (e.g. 'admin info'):
    
       kubectl run --namespace minio minio-client \
         --rm --tty -i --restart='Never' \
         --env MINIO_SERVER_ROOT_USER=$ROOT_USER \
         --env MINIO_SERVER_ROOT_PASSWORD=$ROOT_PASSWORD \
         --env MINIO_SERVER_HOST=minio \
         --image docker.io/bitnami/minio-client:2022.8.11-debian-11-r3 -- admin info minio
    
    To access the MinIO® web UI:
    
    - Get the MinIO® URL:
    
       export NODE_PORT=$(kubectl get --namespace minio -o jsonpath="{.spec.ports[0].nodePort}" services minio)
       export NODE_IP=$(kubectl get nodes --namespace minio -o jsonpath="{.items[0].status.addresses[0].address}")
       echo "MinIO® web URL: http://$NODE_IP:$NODE_PORT/minio"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    查看

    kubectl get pods,svc -n minio -owide
    
    • 1

    在这里插入图片描述
    webUI 登录
    http://local-168-182-110:30901
    账号密码:

    export ROOT_USER=$(kubectl get secret --namespace minio minio -o jsonpath="{.data.root-user}" | base64 -d)
    echo $ROOT_USER
    export ROOT_PASSWORD=$(kubectl get secret --namespace minio minio -o jsonpath="{.data.root-password}" | base64 -d)
    echo $ROOT_PASSWORD
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述
    在这里插入图片描述

    4)安装 mc 测试

    cd /opt/k8s/bigdata/minio
    wget https://dl.min.io/client/mc/release/linux-amd64/mc
    chmod +x mc
    ln -s /opt/k8s/bigdata/minio/mc /usr/bin/mc
    mc --help
    
    • 1
    • 2
    • 3
    • 4
    • 5

    添加MinIO存储服务

    mc config host add minio http://local-168-182-110:30900 admin Kgb4zZT1cU
    mc admin info minio
    # 并创建bucket harbor
    mc mb minio/harbor
    mc ls minio
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

    常用命令参数:

    ls       列出文件和文件夹。
    mb       创建一个存储桶或一个文件夹。
    cat      显示文件和对象内容。
    pipe     将一个STDIN重定向到一个对象或者文件或者STDOUT。
    share    生成用于共享的URL。
    cp       拷贝文件和对象。
    mirror   给存储桶和文件夹做镜像。
    find     基于参数查找文件。
    diff     对两个文件夹或者存储桶比较差异。
    rm       删除文件和对象。
    events   管理对象通知。
    watch    监听文件和对象的事件。
    policy   管理访问策略。
    session  为cp命令管理保存的会话。
    config   管理mc配置文件。
    update   检查软件更新。
    version  输出版本信息。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    5)卸载

    helm uninstall minio -n minio
    kubectl delete ns minio --force
    
    • 1
    • 2

    三、Harbor on K8S 部署

    在这里插入图片描述

    1)创建stl证书

    mkdir /opt/k8s/bigdata/harbor/stl && cd /opt/k8s/bigdata/harbor/stl
    # 生成 CA 证书私钥
    openssl genrsa -out ca.key 4096
    # 生成 CA 证书
    openssl req -x509 -new -nodes -sha512 -days 3650 \
     -subj "/C=CN/ST=Guangdong/L=Shenzhen/O=harbor/OU=harbor/CN=myharbor-minio.com" \
     -key ca.key \
     -out ca.crt
    # 创建域名证书,生成私钥
    openssl genrsa -out myharbor-minio.com.key 4096
    # 生成证书签名请求 CSR
    openssl req -sha512 -new \
        -subj "/C=CN/ST=Guangdong/L=Shenzhen/O=harbor/OU=harbor/CN=myharbor-minio.com" \
        -key myharbor-minio.com.key \
        -out myharbor-minio.com.csr
    # 生成 x509 v3 扩展
    cat > v3.ext <<-EOF
    authorityKeyIdentifier=keyid,issuer
    basicConstraints=CA:FALSE
    keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_names
    
    [alt_names]
    DNS.1=myharbor-minio.com
    DNS.2=*.myharbor-minio.com
    DNS.3=hostname
    EOF
    #创建 Harbor 访问证书
    openssl x509 -req -sha512 -days 3650 \
        -extfile v3.ext \
        -CA ca.crt -CAkey ca.key -CAcreateserial \
        -in myharbor-minio.com.csr \
        -out myharbor-minio.com.crt
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    2)创建secret

    kubectl create ns harbor-minio
    kubectl create secret tls myharbor-minio.com --key myharbor-minio.com.key --cert myharbor-minio.com.crt -n harbor-minio
    kubectl get secret myharbor-minio.com -n harbor-minio
    
    • 1
    • 2
    • 3

    3)下载 harbor 安装包

    cd /opt/k8s/bigdata/harbor
    helm repo add harbor https://helm.goharbor.io
    helm pull harbor/harbor
    tar -xf harbor-1.9.3.tgz
    
    • 1
    • 2
    • 3
    • 4

    4)配置 minio 存储

    persistence:
      enabled: true
      imageChartStorage:
        disableredirect: true
        type: s3
        filesystem:
          rootdirectory: /storage
          #maxthreads: 100
        s3:
          # region描述的是服务器的物理位置,默认是us-east-1(美国东区1),这也是亚马逊S3的默认区域
          region: us-west-1
          bucket: harbor
          # 账号,密码
          accesskey: admin
          secretkey: Kgb4zZT1cU
          # 这里minio.minion是.
          regionendpoint: http://minio.minio:9000
          encrypt: false
          secure: false
          v4auth: true
          chunksize: "5242880"
          rootdirectory: /
          redirect:
            disabled: false
        maintenance:
          uploadpurging:
            enabled: false
        delete:
          enabled: true
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    6)安装 nfs (harbor 本身服务存储)

    harbor本身服务的存储这里使用nfs

    1、所有节点安装nfs
    yum -y install  nfs-utils rpcbind
    
    • 1
    2、在master节点创建共享目录并授权
    mkdir /opt/nfsdata
    # 授权共享目录
    chmod 666 /opt/nfsdata
    
    • 1
    • 2
    • 3
    3、配置exports文件
    cat > /etc/exports<<EOF
    /opt/nfsdata *(rw,no_root_squash,no_all_squash,sync)
    EOF
    # 配置生效
    exportfs -r
    
    • 1
    • 2
    • 3
    • 4
    • 5
    4、启动rpc和nfs(客户端只需要启动rpc服务)(注意顺序)
    systemctl start rpcbind
    systemctl start nfs-server
    systemctl enable rpcbind
    systemctl enable nfs-server
    # 查看
    showmount -e
    showmount -e 192.168.182.110
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    5、客户端
    # 安装
    yum -y install  nfs-utils rpcbind
    # 启动rpc服务
    systemctl start rpcbind
    systemctl enable rpcbind
    # 创建挂载目录
    mkdir /mnt/nfsdata
    # 挂载
    echo "192.168.182.110:/opt/nfsdata /mnt/nfsdata     nfs    defaults  0 1">> /etc/fstab
    mount -a
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    6、创建nfs provisioner和持久化存储SC
    # 添加数据源
    helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
    
    # 开始安装
    helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
      --namespace=nfs-provisioner \
      --create-namespace \
      --set image.repository=willdockerhub/nfs-subdir-external-provisioner \
      --set image.tag=v4.0.2 \
      --set replicaCount=2 \
      --set storageClass.name=nfs-client \
      --set storageClass.defaultClass=true \
      --set nfs.server=192.168.182.110 \
      --set nfs.path=/opt/nfsdata
    
    # 查看
    kubectl get pods,deploy,sc -n nfs-provisioner
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    7)开始安装

    cd /opt/k8s/bigdata/harbor
    helm install myharbor-minio --namespace harbor-minio ./harbor \
      --set expose.ingress.hosts.core=myharbor-minio.com \
      --set expose.ingress.hosts.notary=notary.myharbor-minio.com \
      --set-string expose.ingress.annotations.'nginx\.org/client-max-body-size'="1024m" \
      --set persistence.persistentVolumeClaim.registry.storageClass=nfs-client
      --set persistence.persistentVolumeClaim.jobservice.storageClass=nfs-client \
      --set persistence.persistentVolumeClaim.database.storageClass=nfs-client \
      --set persistence.persistentVolumeClaim.redis.storageClass=nfs-client \
      --set persistence.persistentVolumeClaim.trivy.storageClass=nfs-client \
      --set persistence.persistentVolumeClaim.chartmuseum.storageClass=nfs-client \
      --set persistence.enabled=true \
      --set expose.tls.secretName=myharbor-minio.com \
      --set externalURL=https://myharbor-minio.com \
      --set harborAdminPassword=Harbor12345
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    notes

    NAME: myharbor
    LAST DEPLOYED: Sun Aug 28 11:27:47 2022
    NAMESPACE: harbor-minio
    STATUS: deployed
    REVISION: 1
    TEST SUITE: None
    NOTES:
    Please wait for several minutes for Harbor deployment to complete.
    Then you should be able to visit the Harbor portal at https://myharbor-minio.com
    For more details, please visit https://github.com/goharbor/harbor
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    查看

    kubectl get pods,svc,ingress -n  harbor-minio
    
    • 1

    在这里插入图片描述
    配置/etc/hosts,如果有域名解析就可忽略

    192.168.182.110 myharbor-minio.com
    192.168.182.111 myharbor-minio.com
    192.168.182.112 myharbor-minio.com
    
    • 1
    • 2
    • 3

    Harbor web:https://myharbor-minio.com
    在这里插入图片描述
    在这里插入图片描述

    8)Containerd 配置 Harbor

    以前使用docker-engine的时候,只需要修改/etc/docker/daemon.json就行,但是新版的k8s已经使用containerd了,所以这里需要做相关配置,要不然containerd会失败。证书(ca.crt)可以在页面上下载:
    在这里插入图片描述
    创建域名目录

    mkdir /etc/containerd/myharbor-minio.com
    cp ca.crt /etc/containerd/myharbor-minio.com/
    
    • 1
    • 2

    配置文件:/etc/containerd/config.toml

    [plugins."io.containerd.grpc.v1.cri".registry]
          config_path = ""
    
          [plugins."io.containerd.grpc.v1.cri".registry.auths]
    
          [plugins."io.containerd.grpc.v1.cri".registry.configs]
            [plugins."io.containerd.grpc.v1.cri".registry.configs."myharbor-minio.com".tls]
              insecure_skip_verify = true  #跳过认证
              ca_file = "/etc/containerd/myharbor-minio.com/ca.crt"
            [plugins."io.containerd.grpc.v1.cri".registry.configs."myharbor-minio.com".auth]
              username = "admin"
              password = "Harbor12345"
    
          [plugins."io.containerd.grpc.v1.cri".registry.headers]
    
          [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
            [plugins."io.containerd.grpc.v1.cri".registry.mirrors."myharbor-minio.com"]
              endpoint = ["https://myharbor-minio.com"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    在这里插入图片描述

    重启containerd

    #重新加载配置
    systemctl daemon-reload
    #重启containerd
    systemctl restart containerd
    
    • 1
    • 2
    • 3
    • 4

    9)测试验证

    # tag
    # ctr 有命名空间 namespace 来指定类似于工作空间的隔离区域。使用方法 ctr -n default images ls 来查看 default 命名空间的镜像,不加 -n 参数,默认也是使用default的命名空间。i:images
    ctr -n k8s.io i tag docker.io/bitnami/minio:2022.8.22-debian-11-r0 myharbor-minio.com/bigdata/minio:2022.8.22-debian-11-r0
    
    # 推送镜像到harbor
    ctr --namespace=k8s.io images push myharbor-minio.com/bigdata/minio:2022.8.22-debian-11-r0 --skip-verify --user admin:Harbor12345
    
    # --namespace=k8s.io 指定命名空间,不是必须,根据环境而定
    # --skip-verify 跳过认证
    # --user 指定harbor用户名及密码
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在这里插入图片描述
    在这里插入图片描述
    查看 minio :http://local-168-182-110:30901/

    成查看minio的harbor bucket是否存在docker目录。如果存在说明成。

    在这里插入图片描述
    在这里插入图片描述

    10)卸载

    helm uninstall myharbor-minio -n harbor-minio
    
    • 1

    镜像仓库 Harbor 对接 MinIO 对象存储就到了,有疑问的小伙伴欢迎留言哦,后续会持续分享云原生和大数据相关的文章,请小伙伴耐心等待哦~

  • 相关阅读:
    threejs(12)-着色器打造烟雾水云效果
    ajax请求报文和响应报文一
    msvcp140.dll是什么?msvcp140.dll丢失的有哪些解决方法
    自己动手从零写桌面操作系统GrapeOS系列教程——8.x86介绍
    企业申报两化融合有哪些好处 申报两化融合需要准备哪些材料
    Vue练习CRUD
    双十一“静悄悄”?VR购物拉满沉浸式购物体验
    win10系统错误:Mineud.exe-系统措误 ,无法启动此程序,因为计算机中丢失iUtils.dll。尝试重新安装该程序以解决此问题。
    机器学习入门教学——人工智能、机器学习、深度学习
    Linux基本操作命令
  • 原文地址:https://blog.csdn.net/qq_35745940/article/details/126560091