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:8-jdk-alpine
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.
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.