虛擬機 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
