I'm very new to docker/kubernetes. I built a docker image on my AWS EC2 instance that I can run using
sudo docker run imagename
This runs successfully. I can also see the image exists in the local docker repository when I run
sudo docker image ls
(note: I must use sudo or these commands give permission errors)
Now I'm trying to have kubernetes kick off a job which creates a container with that image, but when I do I get the following error:
Failed to pull image "imagename": rpc error: code = Unknown desc = Error response from daemon: pull access denied for imagename, repository does not exist or may require 'docker login'
Here is the Python/flask code I'm using to try to create the job with the kubernetes API. The job successfully creates on the server, but when I check the kubernetes log that's where I see the error.
config.load_kube_config()
api_client = client.BatchV1Api()
container = client.V1Container(
name="premium",
image="imagename",
resources=client.V1ResourceRequirements(requests={'cpu':'.9'}, limits={'cpu':'2'}),
env=[client.V1EnvVar(name='dataset', value=ds )]
)
# Create and configurate a spec section
template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "premium"}),
spec=client.V1PodSpec(restart_policy="Never", containers=[container]))
# Create the specification of deployment
spec = client.V1JobSpec(
template=template,
backoff_limit=4)
# Instantiate the job object
job = client.V1Job(
api_version="batch/v1",
kind="Job",
metadata=client.V1ObjectMeta(generate_name = 'premium-job-'),
spec=spec)
api_response = api_client.create_namespaced_job("default", job, pretty=True)
I am assuming Docker images are available on all nodes of the Kubernetes cluster. the image should be available on all nodes / you need to mention nodeSelector
property. to run pod on exact same node where your image is present.
Now coming to your error. I saw similar problem with local images. imagePullPolicy
property of the pod is making a problem here. its default value is always
meaning it k8s (more specifically kubelet) try to pull the image to pull image it tries to do docker login (maybe just to compare remote and local images) and gets failed.
How to solve the problem? Set imagePullPolicy
to ifNotPresent
or never
so that it won't try to pull the image (and not tries to do docker login).
I am giving a pointer for a standalone pod. It should be the same for a job. after all, it runs in pod only.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.