Kubernetes ingress controller

10/14/2020

I'm working with microk8s using Kubernetes 1.19. The provided ingress.yaml does not work. Given my troubleshooting below, it seems like ngnix cannot connect to the default-http-backend. Microk8s was installed on a ubuntu 20.04 using snap. I know that there exists a ingress addon. But nonetheless, I would like it to work with this setup.

microk8s kubectl get pods --all-namespaces

kube-ingress           default-http-backend-7744d88f46-45vp7        1/1     Running            0          53m
kube-ingress           nginx-74dd8dd664-7cn67                       0/1     CrashLoopBackOff   15         53m

microk8s kubectl logs -n kube-ingress nginx-74dd8dd664-7cn67

W1014 08:28:14.903056       6 flags.go:249] SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)
W1014 08:28:14.903143       6 client_config.go:543] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I1014 08:28:14.903398       6 main.go:220] Creating API client for https://10.152.183.1:443
I1014 08:28:14.910869       6 main.go:264] Running in Kubernetes cluster version v1.19+ (v1.19.2-34+1b3fa60b402c1c) - git (clean) commit 1b3fa60b402c1c4cb0df8a99b733ad41141a2eb7 - platform linux/amd64
F1014 08:28:14.913646       6 main.go:91] No service with name kube-ingress/default-http-backend found: services "default-http-backend" not found

ingress.yml

apiVersion: v1
kind: Namespace
metadata:
  name: kube-ingress
---
kind: ConfigMap
metadata:
  namespace: kube-ingress
  name: nginx
apiVersion: v1
data:
  proxy-connect-timeout: "15"
  proxy-read-timeout: "600"
  proxy-send-timeout: "600"
  hsts-include-subdomains: "false"
  body-size: "200m"
  server-name-hash-bucket-size: "256"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: default-http-backend
  namespace: kube-ingress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: default-http-backend
  template:
    metadata:
      labels:
        app: default-http-backend
    spec:
      containers:
      - name: default-http-backend
        # Any image is permissable as long as:
        # 1. It serves a 404 page at /
        # 2. It serves 200 on a /healthz endpoint
        image: gcr.io/google_containers/defaultbackend:1.0
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: 10m
            memory: 20Mi
          requests:
            cpu: 10m
            memory: 20Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: kube-ingress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      serviceAccountName: nginx
      containers:
      - image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.31.0
        name: nginx
        imagePullPolicy: Always
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 80
        - containerPort: 443
        args:
        - /nginx-ingress-controller
        - --default-backend-service=kube-ingress/default-http-backend
        - --configmap=kube-ingress/nginx
---
kind: ServiceAccount
apiVersion: v1
metadata:
  name: nginx
  namespace: kube-ingress
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nginx-ingress-newrole
rules:
  - apiGroups:
      - ""
    resources:
      - services
    verbs:
      - get
      - list
      - watch
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nginx-ingress-newrole
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: nginx-ingress-newrole
subjects:
- kind: ServiceAccount
  name: nginx
  namespace: kube-ingress
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nginx-ingress-clusterole
rules:
  - apiGroups:
      - ""
    resources:
      - services
    verbs:
      - get
      - list
      - watch
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nginx-ingress-clusterole
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: nginx-ingress-clusterole
subjects:
- kind: ServiceAccount
  name: nginx
  namespace: kube-ingress
-- nerdizzle
kubernetes
kubernetes-ingress
microk8s
nginx
nginx-ingress

1 Answer

10/20/2020

Issue

As mentioned in the logs

No service with name kube-ingress/default-http-backend found: services "default-http-backend" not found

The main issue here was the lack of default-http-backend service in kube-ingress namespace.

Solution

The solution here is to simply add the default-http-backend service.

You can create it with kubectl expose or yaml file.

-- Jakub
Source: StackOverflow