<p>I am playing with microk8s and I am trying to deploy nextcloud to get more familiar with it. However the deployment of nextcloud went fine, I am facing some issues with setting ingress for that. Maybe you could take a look at my manifests and ingress resource and help find me the problem.</p>
<p>This is the deployment file:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  namespace: nextcloud
  name: nextcloud-service
  labels:
    run: nextcloud-app
spec:
  ports:
    - port: 80
      targetPort: 8080
  selector:
    run: nextcloud-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: nextcloud
  name: nextcloud-deployment
  labels:
    app: nextcloud-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nextcloud-app
  template:
    metadata:
      labels:
        app: nextcloud-app
    spec:
      containers:
      - image: nextcloud:latest
        name: nextcloud
        env:
        - name: NEXTCLOUD_ADMIN_USER
          valueFrom:
            configMapKeyRef:
              name: nextcloud-configuration
              key: nextcloud_admin_user
        - name: NEXTCLOUD_ADMIN_PASSWORD
          valueFrom:
            secretKeyRef:
              name: nextcloud-secret
              key: admin_password
        ports:
        - containerPort: 8080
          name: http
        volumeMounts:
        - name: nextcloud-pv
          mountPath: /var/www/html/data
      volumes:
      - name: nextcloud-pv
        persistentVolumeClaim:
          claimName: nextcloud-pv-claim
</code></pre>
<p>and this is the ingress resource file:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nextcloud-ingress
  namespace: nextcloud
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /nextcloud
        pathType: Prefix
        backend:
          service:
            name: nextcloud-service
            port:
              number: 80
</code></pre>
<p>Following addons are enabled on my microk8s:</p>
<ul>
<li>dns</li>
<li>ingress</li>
</ul>
<p>Now I would like to show you some k8s output.</p>
<p><strong>kubectl -n nextcloud describe svc nextcloud-service</strong></p>
<pre><code>Name:              nextcloud-service
Namespace:         nextcloud
Labels:            run=nextcloud-app
Annotations:       &lt;none&gt;
Selector:          run=nextcloud-app
Type:              ClusterIP
IP:                10.152.183.189
Port:              &lt;unset&gt;  80/TCP
TargetPort:        8080/TCP
Endpoints:         &lt;none&gt;
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>
<p><strong>kubectl -n nextcloud describe ingress nextcloud-ingress</strong></p>
<pre><code>Name:             nextcloud-ingress
Namespace:        nextcloud
Address:          192.168.60.2
Default backend:  default-http-backend:80 (&lt;error: endpoints &quot;default-http-backend&quot; not found&gt;)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /nextcloud   nextcloud-service:80   &lt;none&gt;)
Annotations:  nginx.ingress.kubernetes.io/rewrite-target: /
Events:
  Type    Reason  Age                 From                      Message
  ----    ------  ----                ----                      -------
  Normal  CREATE  11m                 nginx-ingress-controller  Ingress nextcloud/nextcloud-ingress
  Normal  CREATE  11m                 nginx-ingress-controller  Ingress nextcloud/nextcloud-ingress
  Normal  UPDATE  63s (x22 over 11m)  nginx-ingress-controller  Ingress nextcloud/nextcloud-ingress
  Normal  UPDATE  63s (x22 over 11m)  nginx-ingress-controller  Ingress nextcloud/nextcloud-ingress
</code></pre>
<p><strong>kubectl -n ingress logs pod/nginx-ingress-microk8s-controller-k2q6c</strong></p>
<pre><code>I1024 19:56:37.955953       6 status.go:275] updating Ingress nextcloud/nextcloud-ingress status from [{192.168.60.2 }] to [{127.0.0.1 }]
W1024 19:56:37.963861       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:56:37.964276       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192287&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
I1024 19:56:39.491960       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192295&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
W1024 19:56:41.297313       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:57:37.955734       6 status.go:275] updating Ingress nextcloud/nextcloud-ingress status from [{192.168.60.2 }] to [{127.0.0.1 }]
W1024 19:57:37.969214       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:57:37.969711       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192441&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
I1024 19:57:39.492467       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192446&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
W1024 19:57:41.302640       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:58:37.956198       6 status.go:275] updating Ingress nextcloud/nextcloud-ingress status from [{192.168.60.2 }] to [{127.0.0.1 }]
W1024 19:58:37.964655       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:58:37.965017       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192592&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
I1024 19:58:39.493436       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192600&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
W1024 19:58:41.298097       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:59:37.955569       6 status.go:275] updating Ingress nextcloud/nextcloud-ingress status from [{192.168.60.2 }] to [{127.0.0.1 }]
W1024 19:59:37.964975       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:59:37.965045       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192746&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
I1024 19:59:39.491840       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192750&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
W1024 19:59:41.298496       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 20:00:37.956061       6 status.go:275] updating Ingress nextcloud/nextcloud-ingress status from [{192.168.60.2 }] to [{127.0.0.1 }]
W1024 20:00:37.965139       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 20:00:37.965212       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192896&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
I1024 20:00:39.489924       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192904&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
W1024 20:00:41.298762       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 20:01:37.955481       6 status.go:275] updating Ingress nextcloud/nextcloud-ingress status from [{192.168.60.2 }] to [{127.0.0.1 }]
W1024 20:01:37.963612       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 20:01:37.963681       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;193049&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
I1024 20:01:39.490523       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;193058&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
W1024 20:01:41.297141       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
</code></pre>
<p>Calling <a href="http://k8s.ip/nextcloud" rel="nofollow noreferrer">http://k8s.ip/nextcloud</a> results with 503. Any ideas what I am missing?</p>

<p>As I posted in the comments:</p>
<blockquote>
<p>You are receiving 503 code because you have a missmatch in your <code>Service</code> -&gt; <code>.spec.selector</code> (<code>run: nextcloud-app</code>) and your <code>Deployment</code> -&gt; <code>.spec.selector.matchLabels</code> (<code>app: nextcloud-app</code>). You will need to have them both the same. You can see it also when describing the service (no endpoint).</p>
</blockquote>
<p>The issue in this particular setup is that there is a missmatch between a <code>matchLabel</code> in a <code>Deployment</code> and <code>selector</code> in the <code>Service</code>:</p>
<p><code>Deployment</code></p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  replicas: 1
  selector:
    matchLabels:
      app: nextcloud-app # &lt;-- HERE!
</code></pre>
<p><code>Service</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  ports:
    - port: 80
      targetPort: 8080
  selector:
    run: nextcloud-app # &lt;-- HERE!
</code></pre>
<p>To fix that you will need to have both of them matching (for example):</p>
<ul>
<li><code>app: nextcloud-app</code> in a <code>Deployment</code> and a <code>Service</code></li>
</ul>
<hr />
<p>Some of the ways to identify mismatched selector (by using examples from post):</p>
<ul>
<li>Manual inspection of <code>YAML</code> definitions as shown above</li>
<li><code>$ kubectl -n nextcloud describe svc nextcloud-service</code></li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>Name:              nextcloud-service
Namespace:         nextcloud
Labels:            run=nextcloud-app
Annotations:       &lt;none&gt;
Selector:          run=nextcloud-app
Type:              ClusterIP
IP:                10.152.183.189
Port:              &lt;unset&gt;  80/TCP
TargetPort:        8080/TCP
Endpoints:         &lt;none&gt; # &lt;-- HERE
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>
<p>Above <code>describe</code> shows that the service is created but there are no <code>endpoints</code> (<code>Pods</code>) to send the traffic to.</p>
<blockquote>
<p>No endpoint could be also related to the fact that <code>Pod</code> is not <code>Ready</code> or is not in <code>Healthy</code> state</p>
</blockquote>
<ul>
<li><code>$ kubectl get endpoint -n nextcloud</code></li>
</ul>
<pre><code>NAME                 ENDPOINTS            AGE
nextcloud-service    &lt;none&gt;               1m     
</code></pre>
<ul>
<li>Logs from <code>Ingress</code> controller (posted in the question):</li>
</ul>
<pre class="lang-sh prettyprint-override"><code>I1024 19:56:37.955953       6 status.go:275] updating Ingress nextcloud/nextcloud-ingress status from [{192.168.60.2 }] to [{127.0.0.1 }]
W1024 19:56:37.963861       6 controller.go:909] Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.
I1024 19:56:37.964276       6 event.go:278] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;nextcloud&quot;, Name:&quot;nextcloud-ingress&quot;, UID:&quot;913dcf73-e5df-4ad9-a23b-22d6ad8b83a7&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;192287&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'UPDATE' Ingress nextcloud/nextcloud-ingress
</code></pre>
<p><code>&lt;--REDACTED--&gt; Service &quot;nextcloud/nextcloud-service&quot; does not have any active Endpoint.</code></p>
<hr />
<p>I encourage you to check the Helm chart of nextcloud:</p>
<ul>
<li><em><a href="https://github.com/nextcloud/helm/tree/master/charts/nextcloud" rel="nofollow noreferrer">Github.com: Nextcloud: Helm: Charts: Nextcloud</a></em></li>
<li><em><a href="https://microk8s.io/docs/commands" rel="nofollow noreferrer">Microk8s.io: Docs: Commands</a></em></li>
</ul>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Kubernetes.io: Services networking: Service</a></em></li>
<li><em><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Kubernetes.io: Services networking: Ingress</a></em></li>
<li><em><a href="https://microk8s.io/docs/addon-ingress" rel="nofollow noreferrer">Microk8s.io: Docs: Addon Ingress</a></em></li>
</ul>
