虚拟机 ubuntu 安装了docker-ce 和 microk8s
k8s 有自己的docker环境, 不能使用 ubuntu 已经安装了docker的镜像.
所以搭建 docker registry, 在k8s资源配置文件中定义docker的镜像从本机拉取!
1. 搭建Docker Registry
This image contains an implementation of the Docker Registry HTTP API V2 for use with Docker 1.6+. See github.com/docker/distribution for more details about what it is.
Run a local registry: Quick Version
$ docker run -d -p 5000:5000 --restart always --name registry registry:2
Now, use it from within Docker:
$ docker tag account-svc localhost:5000/account-svc
$ docker push localhost:5000/account-svc
查看镜像:
http://localhost:5000/v2/_catalog
2. k8s 使用本地 docker registry
account-svc-deployment.yaml
# https://matthewpalmer.net/kubernetes-app-developer/articles/kubernetes-apiversion-definition-guide.html
# apiVersion: extensions/v1beta1 to apps/v1
# https://stackoverflow.com/questions/58481850/no-matches-for-kind-deployment-in-version-extensions-v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: account-svc-deployment
spec:
replicas: 1
template:
spec:
containers:
- name: account-svc
image: localhost:5000/account-svc
imagePullPolicy: IfNotPresent