<p>My story is:</p>
<p>1, I create a spring-boot project, with a Dockerfile inside.
2, I successfully create the docker image IN LOCAL with above docker file.
3, I have a minikube build a K8s for my local.
4, However, when I try to apply the k8s.yaml, it tells me that there is no such docker image. Obviously my docker app search in public docker hub, so what I can do?</p>
<p>Below is my dockerfile</p>
<pre><code>FROM openjdk:17-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
expose 8080
ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;/app.jar&quot;]
</code></pre>
<p>Below is my k8s.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: pkslow-springboot-deployment
spec:
  selector:
    matchLabels:
      app: springboot
  replicas: 2
  template:
    metadata:
      labels:
        app: springboot
    spec:
      containers:
        - name: springboot
          image: cicdstudy/apptodocker:latest
          ports:
            - containerPort: 8080

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: springboot
  name: pkslow-springboot-service
spec:
  ports:
    - port: 8080
      name: springboot-service
      protocol: TCP
      targetPort: 8080
      nodePort: 30080
  selector:
    app: springboot
  type: NodePort
</code></pre>

JoseLuis
<p>In Kubernetes there is no centralized built-in Container Image Registry exist.
Depending on the container runtime in the K8S cluster nodes you have, it might search first dockerhub to pull images.
Since free pull is not suggested or much allowed by Dockerhub now, it is suggested to create an account for development purposes. You will get 1 private repository and <a href="https://www.docker.com/pricing" rel="nofollow noreferrer">unlimited public repository</a> which means that whatever you pushed to public repositories, there somebody can access it.
If there is no much concern on Intellectual Property issues, you can continue that free account for development purposes. But when going production you need to change that account with a service/robot account.</p>
<ol>
<li><p>Create an Account on DockerHub <a href="https://id.docker.com/login/" rel="nofollow noreferrer">https://id.docker.com/login/</a></p>
</li>
<li><p>Login into your DockerHub account locally on the machine where you are building your container image</p>
<p>docker login --username=yourhubusername --email=youremail@company.com</p>
</li>
<li><p>Build,re-tag and push your image once more (go to the folder where Dockerfile resides)</p>
</li>
</ol>
<ul>
<li>docker build -t mysuperimage:v1 .</li>
<li>docker tag mysuperimage:v1 yourhubusername/mysuperimage:v1</li>
<li>docker push yourhubusername/mysuperimage:v1</li>
</ul>
<ol start="4">
<li>Create a secret for image registry credentials</li>
</ol>
<p>kubectl create secret docker-registry regcred --docker-server=https://index.docker.io/v1/ --docker-username= --docker-password= --docker-email=</p>
<ol start="5">
<li>Create a service account for deployment</li>
</ol>
<p>kubectl create serviceaccount yoursupersa</p>
<ol start="6">
<li>Attach secret to the service account named &quot;yoursupersa&quot;</li>
</ol>
<p>kubectl patch serviceaccount yoursupersa -p '{&quot;imagePullSecrets&quot;: [{&quot;name&quot;: &quot;docker-registry&quot;}]}'</p>
<ol start="7">
<li>Now create your application as deployment resource object in K8S</li>
</ol>
<p>kubectl create deployment mysuperapp --image=yourhubusername/mysuperimage:v1 --port=8080</p>
<ol start="8">
<li>Then patch your deployment with service account which has attached registry credentials.(which will cause for re-deployment)</li>
</ol>
<p>kubectl patch deployment mysuperapp  -p '{&quot;spec&quot;:{&quot;template&quot;:{&quot;spec&quot;:{&quot;serviceAccountName&quot;:&quot;yoursupersa&quot;}}}}'</p>
<ol start="9">
<li>the last step is expose your service</li>
</ol>
<p>kubectl expose deployment/mysuperapp</p>
<p>Then everything is awesome! :)</p>
