Service "smt-local/nginx" does not have any active Endpoint

Setting up Ingress Nginx locally on minikube and it seems I do not have an endpoint. Trying to work out what I am missing here.

Cluster information:

Kubernetes version: 1.19.4 on
Cloud being used: Hypervisor Minikube
Installation method: Homebrew
Host OS: macOS

Ingress Issues

kubectl logs -f pod/ingress-nginx-controller-558664778f-8mw9f -n kube-system

and you could see something like this where it shows there is a 503 and no endpoints

W1214 09:15:02.081958       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 09:23:09.085274       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 09:30:53.087830       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 09:40:00.091440       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 09:47:36.094829       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 09:54:10.096519       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:03:22.099057       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:13:14.101710       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:18:42.103631       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:25:03.105804       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:32:53.107958       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:41:15.110221       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:50:17.112228       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 10:58:53.116279       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
192.168.64.1 - - [14/Dec/2020:11:07:02 +0000] "GET / HTTP/1.1" 503 190 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15" 357 0.000 [smt-local-nginx-8080] [] - - - - c0a25f0592e036fc43cd6493b5d61878
W1214 11:07:17.118076       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
W1214 11:11:46.559640       7 controller.go:937] Service "smt-local/nginx" does not have any active Endpoint.
W1214 11:11:49.892977       7 controller.go:937] Service "smt-local/nginx" does not have any active Endpoint.
W1214 11:11:53.226835       7 controller.go:937] Service "smt-local/nginx" does not have any active Endpoint.
W1214 11:11:56.560180       7 controller.go:937] Service "smt-local/nginx" does not have any active Endpoint.
W1214 11:14:26.120896       7 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
192.168.64.1 - - [14/Dec/2020:11:15:30 +0000] "GET / HTTP/1.1" 503 190 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15" 357 0.000 [smt-local-nginx-8080] [] - - - - 2121620296b56907c2aaef83e9904185

Nginx Service

The Nginx Service I am using now is

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    tier: backend
spec:
  selector:
    app: nginx
    tier: backend
  ports:
  - protocol: TCP
    port: 8080

Nginx Deployment

The Nginx webserver deployment in use is

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: smt-local
spec:
  # autoscale using `kubectl autoscale deployment x --cpu-percent=50 --min=1 --max=10` instead of setting replicas
  # https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/
  # replicas: 2 
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.19.5
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          volumeMounts:
          - name: code-storage
            mountPath: /code
          - name: config
            mountPath: /etc/nginx/conf.d
      volumes:
        - name: code-storage
          persistentVolumeClaim:
            claimName: code-pv-claim
        - name: config
          configMap:
            name: nginx-config
            items:
            - key: config
              path: site.conf

Nginx Deployment Description

kubectl describe deployments.apps nginx 
Name:                   nginx
Namespace:              smt-local
CreationTimestamp:      Mon, 14 Dec 2020 14:25:23 +0700
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        5
RollingUpdateStrategy:  1 max unavailable, 1 max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.19.5
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:
      /code from code-storage (rw)
      /etc/nginx/conf.d from config (rw)
  Volumes:
   code-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  code-pv-claim
    ReadOnly:   false
   config:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      nginx-config
    Optional:  false
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-bfcb6c8b4 (1/1 replicas created)
Events:          <none>

Enpoints missing

What am I missing here? No endpont made:

kubectl describe service nginx
Name:              nginx
Namespace:         smt-local
Labels:            tier=backend
Annotations:       <none>
Selector:          app=nginx,tier=backend
Type:              ClusterIP
IP:                10.99.230.76
Port:              <unset>  80/TCP
TargetPort:        8080/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

Why is no endpoint created?

This fixed it with correct labelling

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    tier: backend
  namespace: smt-local
spec:
  # autoscale using `kubectl autoscale deployment x --cpu-percent=50 --min=1 --max=10` instead of setting replicas
  # https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/
  # replicas: 2 
  selector:
    matchLabels:
      app: nginx
      tier: backend
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        app: nginx
        tier: backend
    spec:
      containers:
        - name: nginx
          image: nginx:1.19.5
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          volumeMounts:
          - name: code-storage
            mountPath: /code
          - name: config
            mountPath: /etc/nginx/conf.d
      volumes:
        - name: code-storage
          persistentVolumeClaim:
            claimName: code-pv-claim
        - name: config
          configMap:
            name: nginx-config
            items:
            - key: config
              path: site.conf

Endpoint got generated

kubectl get endpoints                       
NAME    ENDPOINTS         AGE
nginx   172.17.0.5:8080   5h46m
php     <none>            5h46m