0

I have set up a baremetal k8 cluster ( 1 master node - intel NUC & 2 worker nodes on Raspberry pi). I managed to set up a metal-lb load balance and nginx ingress controller. I have launched two applications, ghost (listens on default port 2368) and nextcloud ( listens on default port 80) . I'm trying to access the applications from public ip myhomeserver.io ( to access the ghost application) and nextcloud.myhomeserver.io ( to access the next cloud application). I can access the ghost application but I can't seem to access nextcloud.Given below are the yaml files for ingress and services. Not sure where am I going wrong.

kubectl get services --all-namespaces
NAMESPACE       NAME                TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)                      AGE
default         kubernetes          ClusterIP      10.96.0.1        <none>            443/TCP                      98d
ghost           ghost-service       ClusterIP      10.107.116.108   <none>            2368/TCP                     7h37m
ingress-nginx   ingress-nginx       LoadBalancer   10.109.177.223   192.168.178.200   80:31619/TCP,443:30365/TCP   7d23h
kube-system     kube-dns            ClusterIP      10.96.0.10       <none>            53/UDP,53/TCP,9153/TCP       98d
nextcloud       nextcloud-service   ClusterIP      10.105.24.162    <none>            8080/TCP                     137m

=============================================================================================================================
NAMESPACE   NAME                HOSTS                       ADDRESS           PORTS   AGE
ghost       ingress-ghost       myhomeserver.io             192.168.178.200   80      7d22h
nextcloud   ingress-nextcloud   nextcloud.myhomeserver.io   192.168.178.200   80      140m


=============================================================================================================================
cat ingress-object-ghost.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-ghost
  namespace: ghost

spec:
  rules:
  - host: myhomeserver.io
    http:
      paths:
      - backend:
          serviceName: ghost-service
          servicePort: 2368


=============================================================================================================================
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-nextcloud
  namespace: nextcloud

spec:
  rules:
  - host: nextcloud.myhomeserver.io
    http:
      paths:
      - backend:
          serviceName: nextcloud-service
          servicePort: 8080

================================================================================================================================

cat ingress-object-nextcloud.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-nextcloud
  namespace: nextcloud

spec:
  rules:
  - host: nextcloud.myhomeserver.io
    http:
      paths:
      - backend:
          serviceName: nextcloud-service
          servicePort: 8080
===================================================================================
apiVersion: apps/v1

kind: Deployment
metadata:
  name:
    deployment-nextcloud
  namespace: nextcloud
  labels:
    env: prod
    app: nextcloud-app

spec:
  template:
    metadata:
      name: nextcloud-app-pod
      labels:
        app:  nextcloud-app
        env:  production
    spec:
      containers:
        - name: nextcloud
          image: arm32v7/nextcloud
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          volumeMounts:
           - mountPath: /var/www/html
             name: nextcloud-data
          securityContext:
            privileged: True


      volumes:
      - name: nextcloud-data
        persistentVolumeClaim:
          claimName: pvc-nextcloud
      nodeSelector:
        kubernetes.io/arch: arm

  replicas: 2
  selector:
    matchLabels:
      app: nextcloud-app


================================================================================================================
apiVersion: v1
kind: Service
metadata:
  name: nextcloud-service
  namespace: nextcloud
  labels:
    app: nextcloud-app
spec:
  type: ClusterIP
  selector:
    app: nextcloud-app
  ports:
  - port: 8080
    targetPort: 8080
    protocol: TCP

1 Answer 1

2

Note your nginx ingress controller is running in the ghost namespace so it only knows about the ghost service. You need to have another ingress controller for your nextcloud namespace if you want to have an ingress there. If you don't want another ingress controller then you can resolve the nextcloud service by targeting its dns in the following way servicename.namespacename.svc.cluster.local

On a side, there is not really a point in dividing your applications that much. Kubernetes already gives you enough privacy among applications in the same namespace.

UPDATE
Ingress that works for you given you have only 1 INGRESS CONTROLLER. Since there are two services I have added a path rule which will be rewritten to / so each service will receive a clean URI. Use myhomeserver.io/ghost to reach ghost and myhomeserver.io/nextcloud to reach nextcloud.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-ghost
  namespace: ghost
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: myhomeserver.io
    http:
      paths:
      - path: /ghost
        backend:
          serviceName: ghost-service
          servicePort: 2368
      - path: /nextcloud
        backend:
          serviceName: nextcloud-service.nextcloud.svc.cluster.local
          servicePort: 8080

UPDATE 2 So your ingress controller is running in the ghost namespace. Thus, your ingress has to be deployed in the ghost namespace. Note the http rules for each host.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-ghost
  namespace: ghost
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: myhomeserver.io
    http:
      paths:
      - path: /
        backend:
          serviceName: ghost-service
          servicePort: 2368
  - host: nextcloud.myhomeserver.io
    http:
      - path: /
        backend:
          serviceName: nextcloud-service.nextcloud.svc.cluster.local
          servicePort: 8080
4
  • @rodgrio ..but I did create an ingress object for each application. As you would see, one for ghost and another for nextcloud. I am a novice and am learning k8 from the set up. Where should I configure the dns as you suggested?
    – IT_novice
    Commented Nov 9, 2019 at 15:18
  • You don't have to do anything, dns is configured by default by kubernetes. No, you did not deploy an INGRESS CONTROLLER in the two namespaces. Note that ingress-controller and ingress are different. To reach nextcloud deploy the ingress yaml I have updated in the answer. Commented Nov 9, 2019 at 18:41
  • thanks for your inputs. I have the URL as subdomains myhomeserver.io and nextcloud.homeserver.io . I guess in this case the path option does not work. How can I configure subdomains ? Again..thanks a ton for your inputs
    – IT_novice
    Commented Nov 9, 2019 at 22:12
  • Sure, just don't forget to upvote my answer haha. Check the last yaml Commented Nov 10, 2019 at 13:55

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