2

i'm noob on Kubernetes. I've configured Kube successfully on my Raspberry pi4b, using kubeadm. I created my first deployment using demo image that expose a simple page with some info and if I logs the pod it says that it listen correctly to the port 8080.

After installing nginx-ingress-controller (status is running) with helm following this https://limpygnome.com/2019/09/21/raspberry-pi-kubernetes-cluster/, I've created a service that points to deployment and an ingress as tutorial explains, but the host that I specified into that ingress is not reachable. Status is running for every pod but I don't understand how to fix it.

I don't know if the problem is the ingress-controller, the ingress or something else.

Here are my yaml:

---
apiVersion: v1
kind: Namespace
metadata:
  name: hello

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: hello-world
  name: hello-world-deploy
  namespace: hello
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      # - image: docker:stable-dind
      - image: pmorjan/demo:latest
        name: hello-world
        securityContext:
          privileged: true
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: hello-world
  name: hello-world-service
  annotations:
    metallb.universe.tf/allow-shared-ip: home-network
  namespace: hello
spec:
  ports:
  - name: http
    port: 80
    targetPort: 8080
  selector:
    app: hello-world
  sessionAffinity: None
  type: LoadBalancer
  loadBalancerIP: 192.168.1.241

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: hello-world-ingress
  namespace: hello
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: ciao.mirco.com
      http:
        paths:
        - path: /hello
          backend:
            serviceName: hello-world-service
            servicePort: 80

Thanks for your help

22
  • you have configure DNS records ? Commented Feb 27, 2020 at 12:29
  • 1
    The los of the pods print that listen to 8080, It seems to work. 192.168.1.241 is an ip that I configured in the service but it's not the node ip. Is this a problem?
    – sP0re90
    Commented Feb 27, 2020 at 13:11
  • 1
    kubectl port-forward svc/hello-world-service 80:80. and open localhost:80 Commented Feb 27, 2020 at 13:12
  • 1
    @HarshManvar yes if I forward the service it works! Now we know that the problem is the ingress, I'd like to use it instead the service. Any ideas?
    – sP0re90
    Commented Feb 27, 2020 at 13:23
  • 1
    in ingress use any host name. in /etc/host add record which point to host. Commented Feb 27, 2020 at 13:56

1 Answer 1

2

When you want to access your pod via ingress you don't need to create a LoadBalancer type service for your pod. Instead you create a LoadBalancer type service for the ingress controller itself and a cluserIP type service for the pod. Also to access it via ciao.mirco.com you need to add an entry into /etc/hosts file of the system where you are accessing as below.

ipaddress ciao.micro.com

The ipadress should be nodeip if you have created a Nodeport type service for ingress controller or LoadBalancer IP if you have created a LoadBalancer type service.

Create a NodePort service for nginx ingress controller in the namespace where nginx ingress controller is deployed.

apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: NodePort
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
    - name: https
      port: 443
      targetPort: 443
      protocol: TCP
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx

After this is created you can check the nodeport(ranging from 30000-32767) assigned to this service.

Find out the IP of the kubernetes node where nginx ingress controller pods are deployed.

Then you can access it via nodeport:nodeip/hello or ciao.micro.com/hello in your browser or via curl nodeip:nodeport/hello -H 'Host:ciao.mirco.com'

24
  • Could you give me an example based on my yaml, please? Thank you
    – sP0re90
    Commented Feb 27, 2020 at 12:55
  • Does to work if you just put the IP 192.168.1.241 in browser? Commented Feb 27, 2020 at 12:58
  • What is the output of kubectl describe svc hello-world-service -n hello. Add the output in question Commented Feb 27, 2020 at 13:10
  • 1
    I think metallb is not needed at all..simple nodeport for ingress controller and clusterip for pod should work..but I am not familiar with raspberry pi Commented Feb 27, 2020 at 13:17
  • 1
    try this curl -D- 192.168.1.100:30506/hello -H 'Host:ciao.mirco.com' Commented Feb 28, 2020 at 12:52

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