You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
迁移镜像仓库到阿里容器镜像服务分几步:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 创建命名空间
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在阿里云容器镜像服务实例列表中创建命名空间,免费的可以创建3个。
|
|
|
|
|
|
|
|
`fs-iot` ,`fs-cloud`,`fs-devops`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 创建访问凭证
|
|
|
|
|
|
|
|
用户名就是阿里账号
|
|
|
|
|
|
|
|
设置固定密码:`V9rtCnt$f`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 构建镜像
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
构建镜像要解决的就是授权问题,不能有交互,自动输入密码。
|
|
|
|
|
|
|
|
通过工具实现
|
|
|
|
|
|
|
|
```shell
|
|
|
|
apt update
|
|
|
|
apt install expect
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在 Jenkins home 目录下增加脚本 `login-ali-repository.sh`:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
#! /usr/bin/expect
|
|
|
|
|
|
|
|
set timeout 3
|
|
|
|
spawn docker login registry.cn-hangzhou.aliyuncs.com -u hi50040201@aliyun.com
|
|
|
|
expect "Password:"
|
|
|
|
send "V9rtCnt\$f\r"
|
|
|
|
interact
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
原来的镜像构建插件不能用
|
|
|
|
|
|
|
|
使用脚本构建:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
比如:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
docker build -t registry.cn-hangzhou.aliyuncs.com/fs-cloud/anxinyun-api:$IMAGE_VERSION /var/jenkins_home/workspace/anxinyun-web.api/
|
|
|
|
|
|
|
|
docker push registry.cn-hangzhou.aliyuncs.com/fs-cloud/anxinyun-api:$IMAGE_VERSION
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![](http://resources.lingwenlong.com/note-img/20211207171700.png)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
下面构建:
|
|
|
|
|
|
|
|
![](http://resources.lingwenlong.com/note-img/20211207171814.png)
|
|
|
|
|
|
|
|
![](http://resources.lingwenlong.com/note-img/20211207171917.png)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
构建成功后到 阿里云 容器镜像服务 仓库中查看:
|
|
|
|
|
|
|
|
![](http://resources.lingwenlong.com/note-img/20211207172101.png)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 如何在项目中使用
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
由于现在镜像仓库设置成私有的,默认是无法拉取的,
|
|
|
|
|
|
|
|
## 创建 secret
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl create secret docker-registry <secret-name> -n <命名空间> \
|
|
|
|
--docker-server=<你的镜像仓库服务器> \
|
|
|
|
--docker-username=<你的用户名> \
|
|
|
|
--docker-password=<你的密码> \
|
|
|
|
--docker-email=<你的邮箱地址>
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl create secret docker-registry registry-anxinyun-secret -n anxinyun \
|
|
|
|
--docker-server='registry.cn-hangzhou.aliyuncs.com' \
|
|
|
|
--docker-username='hi50040201@aliyun.com' \
|
|
|
|
--docker-password='V9rtCnt$f'
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 在yaml 文件中使用secret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
kind: Deployment
|
|
|
|
apiVersion: apps/v1
|
|
|
|
metadata:
|
|
|
|
name: api-anxincloud
|
|
|
|
namespace: anxincloud
|
|
|
|
labels:
|
|
|
|
app: api-anxincloud
|
|
|
|
spec:
|
|
|
|
replicas: 3
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
|
|
|
app: api-anxincloud
|
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
labels:
|
|
|
|
app: api-anxincloud
|
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: api-anxincloud
|
|
|
|
image: registry.cn-hangzhou.aliyuncs.com/fs-cloud/anxinyun-web.api:179.21-12-15
|
|
|
|
command:
|
|
|
|
- node
|
|
|
|
- server.js
|
|
|
|
ports:
|
|
|
|
- name: http-8080
|
|
|
|
containerPort: 8080
|
|
|
|
protocol: TCP
|
|
|
|
...
|
|
|
|
...
|
|
|
|
imagePullSecrets:
|
|
|
|
- name: registry-anxinyun-secret
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|