harbor仓库部署及配置自建证书

habor部署

1.GitHub的官方地址
https://github.com/goharbor/harbor


2.下载harbor
[root@centos201 ~]# wget https://github.com/goharbor/harbor/releases/download/v2.8.2/harbor-offline-installer-v2.8.2.tgz  #


    3.解压软件包
[root@centos201 ~]# tar xf harbor-offline-installer-v2.8.2.tgz -C /linuxmc/softwares/

    
    4.修改配置文件
[root@centos201 ~]# cd /linuxmc/softwares/harbor/
[root@centos201 harbor]# vim harbor.yml
# 添加主机名称
hostname: harbor.linuxmc.com
...
# 设置管理员密码
harbor_admin_password: 1


    5.安装harbor
[root@centos201 harbor]# ./install.sh 

登录harbor
# echo 1 | docker login -u admin --password-stdin harbor.linuxmc.com
# docker login -u admin -p 1 harbor.linuxmc.com
# docker login harbor.linuxmc.com


退出harbor:
# docker logout harbor.linuxmc.com

部署自建证书

1.生成ca的证书
        (1)创建证书目录并进入到证书目录
# mkdir /linuxmc/softwares/harbor/certs/custom/{ca,server,client}
# cd /linuxmc/softwares/harbor/certs/custom


        (2)生成ca的私钥
# openssl genrsa -out ca/ca.key 4096


        (3)生成ca的自签名证书
# openssl req -x509 -new -nodes -sha512 -days 3650 \
 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=linuxmc.com" \
 -key ca/ca.key \
 -out ca/ca.crt


   
   
   2.生成harbor主机证书
    (1)生成harbor主机的私钥
# openssl genrsa -out server/harbor.linuxmc.com.key 4096


    (2)生成harbor主机的证书申请
# openssl req -sha512 -new \
    -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.linuxmc.com" \
    -key server/harbor.linuxmc.com.key \
    -out server/harbor.linuxmc.com.csr
    
    
    (3)生成x509 v3扩展文件
# cat > server/v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=linuxmc.com
DNS.2=linuxmc
DNS.3=harbor.linuxmc.com
EOF


    (4)使用"v3.ext"给harbor主机签发证书
# openssl x509 -req -sha512 -days 3650 \
    -extfile server/v3.ext \
    -CA ca/ca.crt -CAkey ca/ca.key -CAcreateserial \
    -in server/harbor.linuxmc.com.csr \
    -out server/harbor.linuxmc.com.crt
    
    
    (5)将crt文件转换为cert客户端证书文件
# openssl x509 -inform PEM -in server/harbor.linuxmc.com.crt -out server/harbor.linuxmc.com.cert


温馨提示:
    docker程序认为"*.crt"文件是CA证书文件,"*.cert"客户端证书文件,于是上面第五步需要转换一下,其实使用cp一下也是可以的,内容并没有变化。

    
    3.配置harbor服务器使用证书
        (1)修改harbor的配置文件
# vim /linuxmc/softwares/harbor/harbor.yml     
...
hostname: harbor.linuxmc.com
...
https:
  ...
  certificate: /linuxmc/softwares/harbor/certs/custom/server/harbor.linuxmc.com.crt
  private_key: /linuxmc/softwares/harbor/certs/custom/server/harbor.linuxmc.com.key
...
harbor_admin_password: 1

4.客户端配置证书,推荐配置,便于后期维护。
[root@centos201 custom]# ll
total 0
drwxr-xr-x 2 root root  48 Jun 13 11:31 ca
drwxr-xr-x 2 root root   6 Jun 13 11:24 client
drwxr-xr-x 2 root root 149 Jun 13 11:31 server
[root@centos201 custom]# 
[root@centos201 custom]# cp ca/ca.crt server/harbor.linuxmc.com.key server/harbor.linuxmc.com.cert client/
[root@centos201 custom]# 
[root@centos201 custom]# 
[root@centos201 custom]# ll -R
.:
total 0
drwxr-xr-x 2 root root  48 Jun 13 11:31 ca
drwxr-xr-x 2 root root  85 Jun 13 11:43 client
drwxr-xr-x 2 root root 149 Jun 13 11:31 server

./ca:
total 12
-rw-r--r-- 1 root root 2033 Jun 13 11:25 ca.crt
-rw-r--r-- 1 root root 3243 Jun 13 11:25 ca.key
-rw-r--r-- 1 root root   17 Jun 13 11:31 ca.srl

./client:
total 12
-rw-r--r-- 1 root root 2033 Jun 13 11:43 ca.crt
-rw-r--r-- 1 root root 2122 Jun 13 11:43 harbor.linuxmc.com.cert
-rw-r--r-- 1 root root 3243 Jun 13 11:43 harbor.linuxmc.com.key

./server:
total 20
-rw-r--r-- 1 root root 2122 Jun 13 11:31 harbor.linuxmc.com.cert
-rw-r--r-- 1 root root 2122 Jun 13 11:31 harbor.linuxmc.com.crt
-rw-r--r-- 1 root root 1716 Jun 13 11:29 harbor.linuxmc.com.csr
-rw-r--r-- 1 root root 3243 Jun 13 11:29 harbor.linuxmc.com.key
-rw-r--r-- 1 root root  275 Jun 13 11:30 v3.ext
[root@centos201 custom]# 

    
    
    
    5.将客户端证书拷贝到需要登录harbor服务器的节点上
        1)创建自定义域名的证书存放路径(注意,下面的"harbor.linuxmc.com"改成你自己的自签域名)
[root@centos202 ~]# mkdir -pv /etc/docker/certs.d/harbor.linuxmc.com
mkdir: created directory ‘/etc/docker/certs.d’
mkdir: created directory ‘/etc/docker/certs.d/harbor.linuxmc.com’
[root@centos202 ~]# 


        2)拷贝证书文件
[root@centos201 custom]# scp client/* 10.0.0.202:/etc/docker/certs.d/harbor.linuxmc.com/

        3)客户端登录验证 
[root@centos202 ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://tuv7rqqq.mirror.aliyuncs.com"]
}
[root@centos202 ~]# 
[root@centos202 ~]# systemctl restart docker
[root@centos202 ~]# 
[root@centos202 ~]# docker login -u admin -p 1 harbor.linuxmc.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!要在Kubernetes上部署Harbor仓库,您可以按照以下步骤进行操作: 1. 在Kubernetes集群中创建一个命名空间(Namespace),用于部署Harbor。可以使用以下命令创建命名空间: ``` kubectl create namespace harbor ``` 2. 接下来,您需要在Kubernetes中部署一个持久化存储卷(Persistent Volume)和一个持久化存储卷声明(Persistent Volume Claim),用于存储Harbor的数据。您可以根据您的需求选择不同的存储解决方案,如NFS、GlusterFS或Ceph等。以下是一个示例使用NFS的配置文件: ```yaml apiVersion: v1 kind: PersistentVolume metadata: name: harbor-pv labels: type: nfs spec: capacity: storage: 10Gi accessModes: - ReadWriteMany nfs: server: <NFS server IP> path: <NFS server path> --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: harbor-pvc namespace: harbor spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi selector: matchLabels: type: nfs ``` 将上述配置文件保存为`harbor-pv.yaml`,然后使用以下命令创建Persistent Volume和Persistent Volume Claim: ``` kubectl apply -f harbor-pv.yaml ``` 3. 现在,您可以部署Harbor。您可以使用Helm来简化部署过程。首先,添加Harbor的Helm仓库: ``` helm repo add harbor https://helm.goharbor.io ``` 4. 创建一个名为`harbor-values.yaml`的配置文件,并根据您的需求进行配置。以下是一个示例配置文件: ```yaml expose: type: ingress tls: enabled: false ingress: hosts: - harbor.example.com annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/proxy-body-size: "0" persistence: enabled: true existingClaim: harbor/harbor-pvc ``` 在该配置文件中,您可以配置Harbor的访问方式(如Ingress或NodePort)、域名、持久化存储等。 5. 使用以下命令安装Harbor: ``` helm install harbor harbor/harbor -n harbor -f harbor-values.yaml ``` 这将在之前创建的`harbor`命名空间中部署Harbor。 6. 等待部署完成后,您可以使用以下命令查看Harbor的状态: ``` kubectl get pods -n harbor ``` 当所有的Harbor组件都处于`Running`状态时,表示部署成功。 7. 最后,您可以通过配置的访问方式(如Ingress或NodePort)访问Harbor。如果使用Ingress,确保已经配置了域名解析和证书。 希望以上步骤对您有所帮助!如有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值