How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3

In this article we are going to cover How to Install Install Helm 3 on Kubernetes Cluster, install nginx ingress controller kubernetes kops using helm 3, Creating Deployment and service for nginx app and NodeJs app.

Creating Nginx Ingress Resources and Exposing the apps and Pointing Nginx Ingress Loadbalancer in Domain Name provider.

Prerequisites:

  • Kubernetes KOPS Cluster with v1.19.0+

#1: Install Helm 3 on Kubernetes Cluster

Install helm3 on Kubernetes Cluster on Kubernetes Cluster using below command

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

To check helm3 version

helm version

Output:

version.BuildInfo{Version:"v3.5.3", GitCommit:"041ce5a2c17a58be0fcd5f5e16fb3e7e95fea622", GitTreeState:"dirty", GoVersion:"go1.15.8"}

#2: Install Nginx Ingress Controller Kubernetes KOPS using Helm

Add the nginx ingress helm repo in Kubernetes kops cluster, follow this Nginx ingress official page to install latest nginx ingress helm chart

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

Update the helm repo

helm repo update

Install Nginx Ingress Controller Kubernetes KOPS using Helm 3

helm install ingress-nginx ingress-nginx/ingress-nginx

Output:

Output:

NAME: ingress-nginx
LAST DEPLOYED: Sun Apr 11 07:10:01 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The ingress-nginx controller has been installed.
It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status by running 'kubectl --namespace default get services -o wide -w ingress-nginx-controller'

An example Ingress that makes use of the controller:

  apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    annotations:
      kubernetes.io/ingress.class: nginx
    name: example
    namespace: foo
  spec:
    rules:
      - host: www.example.com
        http:
          paths:
            - backend:
                serviceName: exampleService
                servicePort: 80
              path: /
    # This section is only required if TLS is to be enabled for the Ingress
    tls:
        - hosts:
            - www.example.com
          secretName: example-tls

If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:

  apiVersion: v1
  kind: Secret
  metadata:
    name: example-tls
    namespace: foo
  data:
    tls.crt: <base64 encoded cert>
    tls.key: <base64 encoded key>
  type: kubernetes.io/tls

To check nginx ingress controller

kubectl get services ingress-nginx-controller

Output:

NAME                       TYPE           CLUSTER-IP      EXTERNAL-IP                                                               PORT(S)                      AGE
ingress-nginx-controller   LoadBalancer   100.65.85.238   a8e1355c94fdd438a9d207181b50ea1d-213346636.ap-south-1.elb.amazonaws.com   80:30710/TCP,443:31894/TCP   5m15s

We have covered install nginx ingress controller kubernetes kops using helm 3.

#3. Creating Deployment and service for nginx app and NodeJs app

Lets deploy the sample nginx and nodejs app on nginx ingress controller

#3.1. Creating Deployment and service for Nginx app

Create the nginx app deployment

sudo nano nginx-deploy.yml

paste the below deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nginx-web
  namespace: default
  labels:
    app: nginx-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-web
  template:
    metadata:
      labels:
        app: nginx-web
    spec:
      containers:
      - name: nginx
        image: "nginx"

Create the nginx app service

sudo nano nginx-svc.yml

paste the below code

apiVersion: v1
kind: Service
metadata:
  name: nginx-web
  namespace: default
spec:
  selector:
    app: nginx-web
  ports:
  - name: http
    targetPort: 80
    port: 80

deploy the nginx app deployment and service on kubernetes

kubectl create -f nginx-deploy.yml
kubectl create -f nginx-svc.yml

#3.2. Creating Deployment and service for nodejs app

Create the nodejs app deployment

sudo nano nodejs-deploy.yml

paste the below code, here we are using sample nodejs AWS ECR image

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nodejs-app
  namespace: default
  labels:
    app: nodejs-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nodejs-app
  template:
    metadata:
      labels:
        app: nodejs-app
    spec:
      containers:
      - name: nodejs-app
        image: "908198849120.dkr.ecr.ap-south-1.amazonaws.com/nodejsapp:latest"
        ports:
          - containerPort: 3000

Create the nodejs app service

sudo nano nodejs-svc.yml

paste the below code

apiVersion: v1
kind: Service
metadata:
  name: nodejs-app
  namespace: default
spec:
  selector:
    app: nodejs-app
  ports:
  - name: http
    targetPort: 3000
    port: 80

deploy the nodejs app deployment and service on kubernetes

kubectl create -f nodejs-deploy.yml
kubectl create -f nodejs-svc.yml

#4. Creating Nginx Ingress Resources and Exposing the apps

Lets create the nginx ingress resource on Kubernetes to expose the apps

sudo nano nginx-ingress.yml

Paste the below nginx and nodejs app details, here service name should match with service.yml’s

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: nginxapp.fosstechnix.info
    http:
      paths:
      - backend:
          service:
            name: nginx-web
            port:
              number: 80
        path: /
        pathType: Prefix
  - host: nodejsapp.fosstechnix.info
    http:
      paths:
      - backend:
          service:
            name: nodejs-app
            port:
              number: 80
        path: /
        pathType: Prefix

deploy the nginx ingress resource on Kubernetes KOPS cluster

kubectl create -f nginx-ingress.yml

To check Kubernetes pods using kubectl

kubectl get pods

Output:

NAME                                        READY   STATUS    RESTARTS   AGE
ingress-nginx-controller-6f5454cbfb-bdxzr   1/1     Running   0          52m
nginx-web-5bf45d88df-v94h9                  1/1     Running   0          37m
nodejs-app-76c4545979-mjkhp                 1/1     Running   0          3m21s

To check kubernetes deployments using kubectl

kubectl get deploy

Output:

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
ingress-nginx-controller   1/1     1            1           52m
nginx-web                  1/1     1            1           37m
nodejs-app                 1/1     1            1           3m55s

To check Kubernetes service using kubectl

kubectl get svc

Output:

NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP                                                               PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   100.65.85.238    a8e1355c94fdd438a9d207181b50ea1d-213346636.ap-south-1.elb.amazonaws.com   80:30710/TCP,443:31894/TCP   52m
ingress-nginx-controller-admission   ClusterIP      100.67.13.218    <none>                                                                    443/TCP                      52m
kubernetes                           ClusterIP      100.64.0.1       <none>                                                                    443/TCP                      59m
nginx-web                            ClusterIP      100.70.164.135   <none>                                                                    80/TCP                       37m
nodejs-app                           ClusterIP      100.69.84.47     <none>                                                                    80/TCP  

To check kubernetes ingress using kubectl

kubectl get ingress

Output:

NAME            CLASS    HOSTS                                                  ADDRESS                                                                   PORTS   AGE
nginx-ingress   <none>   nginxapp.fosstechnix.info,nodejsapp.fosstechnix.info   a8e1355c94fdd438a9d207181b50ea1d-213346636.ap-south-1.elb.amazonaws.com   80      21m

#5. Pointing Nginx Ingress Loadbalancer in Domain Name provider

To access apps using domain name, here we have pointed loadbalancer url in Domain name provider as CNAME.

How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3 1

Now access nginx app using domain name

nodejsapp.fosstechnix.info
How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3 2

Now access nodejs app using domain name

How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3 3

Conclusion:

we have covered How to Install Install Helm 3 on Kubernetes Cluster, install nginx ingress controller kubernetes kops using helm 3, Creating Deployment and service for nginx app and NodeJs app.

Creating Nginx Ingress Resources and Exposing the apps and Pointing Nginx Ingress Loadbalancer in Domain Name provider.

Related Articles:

Setup Nginx Ingress Controller on Kubernetes using Helm 3

Install Traefik Ingress Controller on Kubernetes using Helm 3

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap