Answers: <p>Your questions in order:</p>
  
  <ol>
  <li>The container not only need to be built, it needs to be in a registry that Kubernetes has access to.  If you are using Docker containers (the default), you can push your container to <a href="https://hub.docker.com/" rel="nofollow noreferrer">Docker Hub</a> so that Kubernetes can retrieve the image.</li>
  <li>They are showing as pending because they do not yet have any containers inside of them.  You've described in the YAML that you want the container in the pod, but Kubernetes has not yet built a working Pod to your specification.</li>
  <li>The deployment is pending because Kubernetes has not yet been able to create the 3 desired pods.</li>
  <li><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Services</a> in Kubernetes are independent of Pods.  This is why the services are shown as available.  So internally, Kubernetes is routing your request to port 80 in the cluster, but no services are yet available on that port.</li>
  </ol>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-20T14:28:55.260Z
Answers: 2019-12-20T14:28:55.260Z
Answers: Wesley Rolnick
Answers: <p>You have to push your image in a registry in order to get the deployment working. Kubernetes does not deal with images (i.e. building, pushing...).</p>
  
  <p>Try <code>kubectl describe deployment mojo-deployment</code>, you'll get more informations about why it's pending (surely because it does not know how to get your Docker image).</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-20T13:03:54.703Z
Answers: 2019-12-20T13:03:54.703Z
Answers: Hedi Nasr
Body: <p>I am using the <code>YAML</code> file to deploy the container on <code>Kubernetes</code> with some replication factor on a hosted machine.</p>
  <h1>YAML File</h1>
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: mojo-deployment
    labels:
      app: mojo
  spec:
    selector:
      matchLabels:
        app: mojo
    replicas: 3
    template:
      metadata:
        labels:
          app: mojo
      spec:
        containers:
          - name: mojo
            image: mojo:1.0.1
            ports:
              - containerPort: 9000
  
  ---
  #Services Info
  apiVersion: v1
  kind: Service
  metadata:
    name: mojo-services
  spec:
    selector:
      app: mojo
    ports:
      - protocol: TCP
        port: 80
        targetPort: 9376
  
  ---
  
  #Ingress Configuration
  apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    name: mojo-ingress
    annotations:
      kubernetes.io/ingress.class: mojo
  spec:
    backend:
      serviceName: mojo-services
      servicePort: 80
  </code></pre>
  <p>Steps:</p>
  <ol>
  <li>Build <code>Docker</code> image using `docker build -t mojo:1.0 .</li>
  <li><code>docker image ls</code> show me an image id.</li>
  <li>Skipping <code>docker build</code> command to deploy image on container. Do I need to do it? or <code>kubectl</code> service will take care of it.</li>
  <li>Run <code>kubectl apply -f Prod.yaml</code>. It shows</li>
  </ol>
  <blockquote>
  <p>deployment.apps/mojo-deployment created</p>
  <p>service/mojo-services created</p>
  <p>ingress.networking.k8s.io/mojo-ingress created</p>
  </blockquote>
  <ol start="5">
  <li><p><code>kubectl get service</code> returns</p>
  <p><a href="https://i.sstatic.net/2mjol.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2mjol.png" alt="" /></a></p>
  </li>
  <li><p><code>kubectl get pod</code> returns
  <a href="https://i.sstatic.net/mQZY2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mQZY2.png" alt="" /></a></p>
  </li>
  <li><p><code>kubectl get deployment</code> returns
  <a href="https://i.sstatic.net/CulrZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CulrZ.png" alt="enter image description here" /></a></p>
  </li>
  </ol>
  <p>Questions?</p>
  <ol>
  <li><p>Do I need to build the container before deploying <code>YAML</code> file? I tried it but still <code>kubernetes</code> not running.</p>
  </li>
  <li><p>Why all pods are showing <code>Pending</code> status.</p>
  </li>
  <li><p>Deployment is also showing <code>pending</code> status.</p>
  </li>
  <li><p>Though I am trying to access the <code>Ingress</code> with :80 and cannot access it.</p>
  </li>
  </ol>
  
Tags: <docker><kubernetes><containers><dockerfile>
Title: Configure Kubernetes with docker container on Ubuntu VM
UserDisplayName: Amit Pal
ThreadText: # Configure Kubernetes with docker container on Ubuntu VM
  
  (Asked by: username_0 on 2019-11-24)
  
  I am using the `YAML` file to deploy the container on `Kubernetes` with some replication factor on a hosted machine.
  
  # YAML File
  
  ```
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: mojo-deployment
    labels:
      app: mojo
  spec:
    selector:
      matchLabels:
        app: mojo
    replicas: 3
    template:
      metadata:
        labels:
          app: mojo
      spec:
        containers:
          - name: mojo
            image: mojo:1.0.1
            ports:
              - containerPort: 9000
  
  ---
  #Services Info
  apiVersion: v1
  kind: Service
  metadata:
    name: mojo-services
  spec:
    selector:
      app: mojo
    ports:
      - protocol: TCP
        port: 80
        targetPort: 9376
  
  ---
  
  #Ingress Configuration
  apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    name: mojo-ingress
    annotations:
      kubernetes.io/ingress.class: mojo
  spec:
    backend:
      serviceName: mojo-services
      servicePort: 80
  
  ```
  
  Steps:
  
  1. Build `Docker` image using `docker build -t mojo:1.0 .
  2. `docker image ls` show me an image id.
  3. Skipping `docker build` command to deploy image on container. Do I need to do it? or `kubectl` service will take care of it.
  4. Run `kubectl apply -f Prod.yaml`. It shows
  
  > deployment.apps/mojo-deployment created
  >
  > service/mojo-services created
  >
  > ingress.networking.k8s.io/mojo-ingress created
  
  5. `kubectl get service` returns
  
     [![](https://i.sstatic.net/2mjol.png)](https://i.sstatic.net/2mjol.png)
  6. `kubectl get pod` returns
     [![](https://i.sstatic.net/mQZY2.png)](https://i.sstatic.net/mQZY2.png)
  7. `kubectl get deployment` returns
     [![enter image description here](https://i.sstatic.net/CulrZ.png)](https://i.sstatic.net/CulrZ.png)
  
  Questions?
  
  1. Do I need to build the container before deploying `YAML` file? I tried it but still `kubernetes` not running.
  2. Why all pods are showing `Pending` status.
  3. Deployment is also showing `pending` status.
  4. Though I am trying to access the `Ingress` with :80 and cannot access it.
  
  **Tags:** docker, kubernetes, containers, dockerfile
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-12-20. Score: 1
  
  Your questions in order:
  
  1. The container not only need to be built, it needs to be in a registry that Kubernetes has access to. If you are using Docker containers (the default), you can push your container to [Docker Hub](https://hub.docker.com/) so that Kubernetes can retrieve the image.
  2. They are showing as pending because they do not yet have any containers inside of them. You've described in the YAML that you want the container in the pod, but Kubernetes has not yet built a working Pod to your specification.
  3. The deployment is pending because Kubernetes has not yet been able to create the 3 desired pods.
  4. [Services](https://kubernetes.io/docs/concepts/services-networking/service/) in Kubernetes are independent of Pods. This is why the services are shown as available. So internally, Kubernetes is routing your request to port 80 in the cluster, but no services are yet available on that port.
  
  
  ---
  
  ### Answer by username_2 on 2019-12-20. Score: 1
  
  You have to push your image in a registry in order to get the deployment working. Kubernetes does not deal with images (i.e. building, pushing...).
  
  Try `kubectl describe deployment mojo-deployment`, you'll get more informations about why it's pending (surely because it does not know how to get your Docker image).
  
  
  ---
  
  