I'm trying kubernetes and making some progress, but I'm running into an issue with ingress when trying to make my hello world app publicly available.
SUCCESS WITH DEPLOYMENT AND SERVICE
I created a simple hello world type of nodejs app and pushed the image to my docker hub johnlai2004/swarm2. I successfully created a deployment and service with this yaml file:
nodejs.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-hello
labels:
app: nodejs-hello
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-hello
template:
metadata:
labels:
app: nodejs-hello
spec:
containers:
- name: nodejs-hello
image: johnlai2004/swarm2
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-hello-service
spec:
selector:
app: nodejs-hello
type: LoadBalancer
ports:
- protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30000
I uploaded these files to a VPS with a new installation of ubuntu 20.04, minikube, kubectl and docker.
I ran the following commands and got the results I wanted:
minikube start --driver=docker
kubectl apply -f nodejs.yaml
minikube service nodejs-hello-service
|-----------|----------------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------------|-------------|---------------------------|
| default | nodejs-hello-service | 3000 | http://192.168.49.2:30000 |
|-----------|----------------------|-------------|---------------------------|
When I do a wget
http://192.168.49.2:30000, I get an index.html file that says hello from nodejs-hello-556dc868-6lrdz at 12/19/2021, 10:29:56 PM. This is perfect.
FAILURE WITH INGRESS
Next, I want to use ingress so that I can see the page at
http://website.example.com (replace website.example.com with the actual domain that points to my server). I put this file on my server:
nodejs-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-ingress
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: website.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nodejs-hello-service
port:
number: 3000
And I ran the commands
minikube addons enable ingress
kubectl apply -f nodejs-ingress.yaml
kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
nodejs-ingress <none> website.example.com localhost 80 15m
But when I visit
http://website.example.com with my browser, the browser says it can't connect. Using wget
http://website.example.com gave the same connection issue.
Can someone point out what I may have done wrong?
-----------------------------
Code from
linux vps hosting.