Before onboarding to the enterprise k8s / AWS EKS, I am using docker-desktop
for local k8s testing on Mac with the following Dockerfile:
FROM openjdk:11-jre-slim
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
with the following deployment steps to docker-desktop
:
docker build . -t cpchung/rema
kubectl create deployment rema --image=cpchung/rema --dry-run -o=yaml > deployment.yaml
echo --- >> deployment.yaml
kubectl create service clusterip rema --tcp=8080:8080 --dry-run -o=yaml >> deployment.yaml
kubectl apply -f deployment.yaml
This generates the deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: rema
name: rema
spec:
replicas: 1
selector:
matchLabels:
app: rema
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: rema
spec:
containers:
- image: cpchung/rema
name: rema
resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: rema
name: rema
spec:
ports:
- name: 8080-8080
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: rema
type: ClusterIP
status:
loadBalancer: {}
and test the deployment with the following health check:
kubectl port-forward svc/rema 8080:8080
curl localhost:8080/actuator/health
But I am getting this error:
robinhood $ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/rema-57df6cf5fc-px8pc 0/1 ImagePullBackOff 0 4m29s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 18h
service/rema ClusterIP 10.100.78.60 <none> 8080/TCP 152m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/rema 0/1 1 0 4m29s
NAME DESIRED CURRENT READY AGE
replicaset.apps/rema-57df6cf5fc 1 1 0 4m29s
robinhood $ kubectl logs rema-57df6cf5fc-px8pc
Error from server (BadRequest): container "rema" in pod "rema-57df6cf5fc-px8pc" is waiting to start: image can't be pulled
But I really have the image from dockers:
robinhood $ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cpchung/rema latest 14a4957873cd 2 hours ago 224MB
What could be wrong here? I am using mac with docker-desktop.
Kubernetes doesn't directly pull from the registry. First it searches for the image on local storage and then docker registry. Create a deployment kubectl run test --image=test:test8970 It won't go to docker registry to pull the image. It will bring up the pod instantly.
The kubelet, the agent that runs on each node in the cluster, calls the container runtime and instructs it to pull the image. If it fails, it reports back this error. It can be caused by typos, wrong tag names, missing registry secrets. If no images can be pulled, there might be a problem with your network setup.
The status ImagePullBackOff means that a container could not start because Kubernetes could not pull a container image (for reasons such as invalid image name, or pulling from a private registry without imagePullSecret ). The BackOff part indicates that Kubernetes will keep trying to pull the image, with an increasing back-off delay.
If you would like to always force a pull, you can do one of the following: Set the imagePullPolicy of the container to Always. Omit the imagePullPolicy and use :latest as the tag for the image to use; Kubernetes will set the policy to Always when you submit the Pod.
https://stackoverflow.com/a/52763242/3514300 should solve the issue for you
In your deployment add imagePullPolicy: Never
By default for images tagged with no tag are given the latest
tag in docker. Kubernetes by default tries to pull the images for latest
tag and it wasn't able to find the image in dockerhub. https://kubernetes.io/docs/concepts/containers/images/#updating-images
Other way is to push your image to dockerhub too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With