构建docker私有仓库+k8s-pod应用

时间:2023-02-15 16:27:44

环境版本
系统:centos7.4
docker-compose version 1.26.2
docker-py version: 4.3.0
CPython version: 2.7.5
docker-version:1.19.0
1安装docker(这个就yum install docker就要的了)
2安装docker-compose
#yum install pip -y
#pip install  docker-compose
#pip install --upgrade pip
#pip install  docker-compose
3下载harbor文件
wget http://harbor.orientsoft.cn/harbor-1.2.0/harbor-offline-installer-v1.4.0.tgz
解压
tar -zxvf harbor-offline-installer-v1.4.0.tgz
编辑harbor的配置文件修改为本地IP就行了
vim harbor/harbor.cfg
指定 harbor 的主机名,可以是IP地址,也可以是域名(不能注释再指定)
hostname = 192.168.1.9
指定用户访问使用的协议,默认http  
ui_url_protocol = http
指定 mysql 数据库管理员密码
db_password = 123456

4开始安装harbor
运行当前目录的install.sh 文件安装
./install.sh
会下载要用的镜像
vmware/clair-photon                                              v2.0.1-v1.4.0       a1df3526fe43        2 years ago         300MB
vmware/notary-server-photon                                      v0.5.1-v1.4.0       3edfddb8ece2        2 years ago         211MB
vmware/notary-signer-photon                                      v0.5.1-v1.4.0       cc70a05cdb6a        2 years ago         209MB
vmware/registry-photon                                           v2.6.2-v1.4.0       8920f621ddd1        2 years ago         198MB
vmware/nginx-photon                                              v1.4.0              20c8a01ac6ab        2 years ago         135MB
vmware/harbor-log                                                v1.4.0              9e818c7a27ab        2 years ago         200MB
vmware/harbor-jobservice                                         v1.4.0              29c14d91b043        2 years ago         191MB
vmware/harbor-ui                                                 v1.4.0              6cb4318eda6a        2 years ago         210MB
vmware/harbor-adminserver                                        v1.4.0              8145970fa013        2 years ago         182MB
vmware/harbor-db                                                 v1.4.0              c38da34727f0        2 years ago         521MB
vmware/mariadb-photon                                            v1.4.0              8457013cf6e3        2 years ago         521MB
vmware/postgresql-photon                                         v1.4.0              59aa61520094        2 years ago         221MB
vmware/harbor-db-migrator                                        1.4                 7a4d871b612e        2 years ago         1.15GB
vmware/photon                                                    1.0                 9b411d78ad9e        2 years ago         130MB

5完成后页面访问192.168.1.9  用户名 admin 密码 123456 就可以看到页面了

6上传镜像
在要上传的服务器先登录到harbor
docker login -u admin -p 123456  192.168.1.9

将要上传的镜像重命名(nginx)
docker tag e6e4e4a2ba1b 192.168.1.9/song(仓库名)/nginx:1.17
上传
docker push 192.168.1.9/song(仓库名)/nginx:1.17

下载同理
先登录
docker login -u admin -p 123456  192.168.1.9
下载
docker pull 192.168.1.9/song(仓库名)/nginx:1.17

稍后跟新k8s链接仓库并使用
k8s拉取私有镜像

1先创建基于docker-registry的secret 方便于拉去镜像是pod直接认证镜像仓库 就不用登录这一面了

kubectl create secret docker-registry song-docker-key --docker-server=192.168.1.9 --docker-username=admin --docker-password=123456 --docker-email=admin@qq.com

2在创建pod的yaml文件里containers同级添加参数

apiVersion: v1
kind: Pod
metadata:
  name: secret-file-pod
spec:
  containers:
  - name: mypod
    image: redis
  imagePullSecrets:                         # 获取镜像需要的用户名密码
   - name: song-docker-key

重启pod完成