# 1. 创建阿里云私有Registry
https://cr.console.aliyun.com/cn-shanghai/instance/repositories
参考阿里云官方文档,仓库名称:nginx pull地址:registry.cn-shanghai.aliyuncs.com/ligan0404/nginx
# 2. 将镜像推送到Registry
docker login --username=295******@qq.com registry.cn-shanghai.aliyuncs.com
docker tag [ImageId] registry.cn-shanghai.aliyuncs.com/ligan0404/nginx:[镜像版本号]
docker push registry.cn-shanghai.aliyuncs.com/ligan0404/nginx:[镜像版本号]
1
2
3
2
3
备注:即修改镜像名称和tag同镜像仓库一致
# 3. 从Registry中拉取镜像
docker login --username=295******@qq.com registry.cn-shanghai.aliyuncs.com
docker pull registry.cn-shanghai.aliyuncs.com/ligan0404/nginx:1.19.0-alpine
1
2
2
# 4. 编写secret.yaml
apiVersion: v1
data:
.dockerconfigjson: >-
xxxxxxxxxxxxxxxxx
immutable: false
kind: Secret
metadata:
name: ali-secret
namespace: default
type: kubernetes.io/dockerconfigjson
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 5. 编写deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: registry.cn-shanghai.aliyuncs.com/ligan0404/nginx:1.19.0-alpine
ports:
- containerPort: 3000
imagePullSecrets:
- name: ali-secret
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
在pull镜像时,需要用docker私有仓库登录账号和密码,设置命令如下:
kubectl create secret docker-registry regsecret --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
1
# 6. 编写service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
type: NodePort
ports:
- targetPort: 80
nodePort: 32000
port: 80
protocol: TCP
selector:
app: nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 7. 创建secret delopy service
kubectl create -f secret.yaml
kubectl create -f deploy.yaml
kubectl create -f service.yaml
1
2
3
2
3