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
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'