在minikube中使用本地镜像很麻烦,经过本人验证,如下方法可以通过:
1.使用eval $(minikube docker-env)设置环境变量
2.使用Minikube的Docker守护程序构建映像(例如docker build -t my-image .)
3.像pod标签一样在pod规范中设置图像(例如my-image)
4.将imagePullPolicy设置为IfNotPresent或者Never,否则Kubernetes将尝试下载图像。
重要说明:您必须在要使用的每个终端上运行eval $(minikube docker-env),因为它仅为当前shell会话设置环境变量。
举例:
[mike@localhost ~]$ eval $(minikube docker-env)
[mike@localhost Dokcer]$ ls
Dockerfile main OnDemandBuild.py
[mike@localhost Dokcer]$ docker build -t intel:1.0.0 .
Sending build context to Docker daemon 9.389 MB
Step 1/13 : FROM docker.io/centos
latest: Pulling from library/centos
*****************************************
*****************************************
Step 13/13 : ENTRYPOINT ["./intelPerf"]
---> Running in 89e116f8d9af
Removing intermediate container 89e116f8d9af
---> b5a9764a6631
Successfully built b5a9764a6631
Successfully tagged intel:1.0.0
之后便可以使用在minikube部署deployment时使用intel:1.0.0这个镜像了。
deployment的yaml文件如下:
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: intel-deployment
spec:
selector:
matchLabels:
app: intel
replicas: 1 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: intel
spec:
containers:
- name: intel
image: intel:1.0.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9527
网友评论