Ingress
Make sure you are in the correct namespace.
Enable Ingress Controller
In case of using minikube
you need to enable NGNIX Ingress controller.
minikube addons enable ingress -p devnation
Wait a minute or so and verify that it has been deployed correctly:
kubectl get pods -n ingress-nginx
ingress-nginx-admission-create-lqfh2 0/1 Completed 0 6m28s
ingress-nginx-admission-patch-z2lzj 0/1 Completed 2 6m28s
ingress-nginx-controller-69ccf5d9d8-95xgp 1/1 Running 0 6m28s
Deploy Application
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: quarkus-demo-deployment
spec:
replicas: 1
selector:
matchLabels:
app: quarkus-demo
template:
metadata:
labels:
app: quarkus-demo
env: dev
spec:
containers:
- name: quarkus-demo
image: quay.io/rhdevelopers/quarkus-demo:v1
imagePullPolicy: Always
ports:
- containerPort: 8080
EOF
Expose the service:
kubectl expose deployment quarkus-demo-deployment --type=NodePort --port=8080
kubectl get service quarkus-demo-deployment
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
quarkus-demo-deployment NodePort 10.105.106.66 <none> 8080:30408/TCP 11s
IP=$(minikube ip -p devnation)
PORT=$(kubectl get service/quarkus-demo-deployment -o jsonpath="{.spec.ports[*].nodePort}")
If using a hosted Kubernetes cluster like OpenShift then use curl and the EXTERNAL-IP address with port 8080
or get it using kubectl
:
IP=$(kubectl get service quarkus-demo-deployment -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
PORT=$(kubectl get service quarkus-demo-deployment -o jsonpath="{.spec.ports[*].port}")
If you are in AWS, you need to get the hostname instead of ip.
|
IP=$(kubectl get service quarkus-demo-deployment -o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
Curl the Service:
curl $IP:$PORT
Configuring Ingress
An Ingress resource is defined as:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: kube-devnation.info
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: quarkus-demo-deployment
port:
number: 8080
kubectl apply -f apps/kubefiles/demo-ingress.yaml
Get the information from the Ingress resource:
kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
example-ingress <none> kube-devnation.info 192.168.99.115 80 68s
You need to wait until address field is set. It might take some minutes.
Modify the /etc/hosts
to point the hostname to the Ingress address.
If you are using minikube, use the minikube ip -p kube as address because the Ingress IP is an internal IP.
|
/etc/hosts
172.17.0.15 kube-devnation.info
curl kube-devnation.info
Supersonic Subatomic Java with Quarkus quarkus-demo-deployment-8cf45f5c8-qmzwl:1
Second Deployment
Deploy a second version of the service:
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: mynode-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mynode
template:
metadata:
labels:
app: mynode
spec:
containers:
- name: mynode
image: quay.io/rhdevelopers/mynode:v1
ports:
- containerPort: 8000
EOF
kubectl expose deployment mynode-deployment --type=NodePort --port=8000
Ingress Update
Then you need to update the Ingress resource with the new path
:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: kube-devnation.info
http:
paths:
- path: /
backend:
serviceName: quarkus-demo-deployment
servicePort: 8080
- path: /v2
backend:
serviceName: mynode-deployment
servicePort: 8000
kubectl apply -f apps/kubefiles/demo-ingress-2.yaml
Test it:
curl kube-devnation.info
Supersonic Subatomic Java with Quarkus quarkus-demo-deployment-8cf45f5c8-qmzwl:2
curl kube-devnation.info/v2
Node Bonjour on mynode-deployment-77c7bf857d-5nfl4 0