Ingress Controller Using NGINX
Deploy Ingress controller and default backend.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
Verify ingress controller Pod started or not
kubectl get all -n ingress-nginx
NAME READY STATUS RESTARTS AGE
pod/nginx-ingress-controller-5bffb7dd4d-58vpp 1/1 Running 0 6m34s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ingress-nginx LoadBalancer 172.168.6.87 192.168.31.51 80:31892/TCP,443:31951/TCP 4m34s
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-ingress-controller 1 1 1 1 6m34s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-ingress-controller-5bffb7dd4d 1 1 1 6m34s
Verify NGINX ingress version
POD_NAMESPACE=ingress-nginx
POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io/name=ingress-nginx -o jsonpath='{.items[0].metadata.name}')
kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version
-------------------------------------------------------------------------------
NGINX Ingress controller
Release: 0.19.0
Build: git-05025d6
Repository: https://github.com/kubernetes/ingress-nginx.git
-------------------------------------------------------------------------------
Create ingress-nginx service
kind: Service
apiVersion: v1
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
externalTrafficPolicy: Local
type: LoadBalancer
selector:
app.kubernetes.io/name: ingress-nginx
ports:
- name: http
port: 80
targetPort: http
- name: https
port: 443
targetPort: https
kubectl create -f ingress-nginx.yaml
kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx LoadBalancer 172.168.34.173 192.168.78.51 80:31709/TCP,443:32254/TCP 39s
Deploy coffee
and tea
application and configure ingress to access it with same hostname
IC_IP=192.168.78.51
IC_HTTPS_PORT=443
kubectl create -f https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/master/examples/complete-example/cafe-ingress.yaml
kubectl create -f https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/master/examples/complete-example/cafe.yaml
Deploy certificates and key for HTTPS access
kubectl create -f https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/master/examples/complete-example/cafe-secret.yaml
Wait for few minites and make sure you got ADDRESS field populated in ingress
kubectl get ingresses.extensions
NAME HOSTS ADDRESS PORTS AGE
cafe-ingress cafe.example.com 192.168.78.51 80, 443 2m21s
curl --resolve cafe.example.com:$IC_HTTPS_PORT:$IC_IP https://cafe.example.com:$IC_HTTPS_PORT/coffee --insecure
Server address: 10.10.2.25:80
Server name: coffee-56668d6f78-mdghx
Date: 04/Oct/2018:15:20:50 +0000
URI: /coffee
curl --resolve cafe.example.com:$IC_HTTPS_PORT:$IC_IP https://cafe.example.com:$IC_HTTPS_PORT/tea --insecure
Server address: 10.10.1.23:80
Server name: tea-85f8bf86fd-49tp4
Date: 04/Oct/2018:15:20:58 +0000
URI: /tea
Request ID: 535dc70dab7f31c3d22b317d4570a289
You may also add entries in Host file (/etc/hosts
in Linux and C:\Windows\System32\drivers\etc\hosts
for windows )
192.168.78.51 cafe.example.com
Now you can use your browser to access the application