Minikube services work when run from command line, but applying through YAML doesn't work

1/9/2020

Heres image of my Kubernetes services.

My kubernetes services

Todo-front-2 is working instance of my app, which I deployed with command line:

kubectl run todo-front --image=todo-front:v7 --image-pull-policy=Never
kubectl expose deployment todo-front --type=NodePort --port=3000

And it's working great. Now I want to move on and use todo-front.yaml file to deploy and expose my service. Todo-front service refers to my current try on it. My deployment file looks like this:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: todo-front
spec:
  replicas: 1
  selector:
    matchLabels:
      app: todo-front
  template:
    metadata:
      labels:
        app: todo-front
    spec:
      containers:
        - name: todo-front
          image: todo-front:v7
          env:
          - name: REACT_APP_API_ROOT
            value: "http://localhost:12000"
          imagePullPolicy: Never
          ports:
            - containerPort: 3000
---
kind: Service
apiVersion: v1
metadata:
  name: todo-front
spec:
  type: NodePort
  ports:
    - port: 3000
      targetPort: 3000
  selector:
    app: todo-front

I deploy it using:

kubectl apply -f deployment/todo-front.yaml

Here is the output

Output for deploying app

But when I run

minikube service todo-front

It redirects me to URL saying "Site can't be reached". I can't figure out what I'm doing wrong. Ports should be ok, and my cluster should be ok since I can get it working by only using command-line without external YAML files. Both deployments are also using the same docker-image. I have also tried changing all ports now "3000" to something different, in case they clash with existing deployment todo-front-2, no luck. Here is also a screenshot of pods and their status:

enter image description here

Anyone with more experience with Kube and Docker cares to take a look? Thank you!

-- Riku
docker
kubernetes
minikube

1 Answer

1/9/2020

You can run below commands to generate the yaml files without applying it to the cluster and then compare it with the yamls you manually created and see if there is a mismatch. Also instead of creating yamls manually yourself you can apply the generated yamls itself.

kubectl run todo-front --image=todo-back:v7 --image-pull-policy=Never --dry-run -o yaml > todo-front.yaml


kubectl expose deployment todo-front --type=NodePort --port=3000 --dry-run -o yaml > todo-depoloyment.yaml
-- Arghya Sadhu
Source: StackOverflow