0

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

  1. kubectl get service returns

  2. kubectl get pod returns

  3. kubectl get deployment returns enter image description here

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.

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).

| improve this answer | |
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 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 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.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.