In the previous post we’ve looked into Kubernetes Services which are essentially load balancing constructs layered on top of Pods. The Service construct provides basic routing and discovery of your applications within the Kubernetes platform, however, sometimes your requirement might be to expose your applications running on Kubernetes to the outside of cluster.

And that’s where Kubernetes Ingress object comes in with its ability to route traffic from the outside of Kubernetes all the way down to a container running inside a Pod. This concept is also known as a reverse proxy.

More Details: Kubernetes Ingress and Kubernetes Ingress Controller


Create Ingress

Let’s start with creating Ingress workloads. You can generally do this either by adopting Imperative or Declarative syntax with the kubectl create command.

More Details: kubectl create

Imperative

kubectl create ingress [INGRESS NAME]

Declarative

kubectl apply -f [INGRESS TEMPLATE].yaml

[INGRESS TEMPLATE].yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: [INGRESS NAME]
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /my-path
        pathType: Prefix
        backend:
          service:
            name: my-app
            port:
              number: 80

List Ingress

To find out what Ingress workloads are running and in which Namespaces you’ll probably want to use some of these kubectl get ingress commands.

More Details: kubectl get

List All Ingress in Namespace

kubectl get ingress -n [NAMESPACE]

List All Ingress in All Namespaces

kubectl get ingress --all-namespaces

List All Ingress with Labels

kubectl get ingress --all-namespaces --show-labels

Ingress Details

These commands will allow you to look deeper into your chosen Ingress where you’ll find out all the Ingress details, labels, ports & IP addresses.

More Details: kubectl describe

Get Ingress

kubectl get ingress [INGRESS NAME] -n [NAMESPACE]

Get Ingress – Wide Output

kubectl get ingress [INGRESS NAME] -n [NAMESPACE] -o wide

Get Ingress – YAML Output

kubectl get ingress [INGRESS NAME] -n [NAMESPACE] -o yaml

Export Ingress – YAML Output to File

kubectl get ingress [INGRESS NAME] -n [NAMESPACE] -o yaml --export > [FILE NAME].yaml

Describe Ingress

kubectl describe ingress [INGRESS NAME] -n [NAMESPACE]

Patch Ingress

To modify an existing Ingress directly on the Kubernetes data plane use the kubectl patch command.

More Details: kubectl patch

Patch Ingress with bash

kubectl patch ingress [INGRESS NAME] -n [NAMESPACE] -p "$(cat [INGRESS TEMPLATE].yaml)"

Patch Ingress with Powershell

kubectl patch ingress [INGRESS NAME] -n [NAMESPACE] -p $(Get-Content [INGRESS TEMPLATE].yaml -Raw)

Delete Ingress

Finally, to dispose of an Ingress workload simply use the kubectl delete command allowing you to target single Ingress or even filter on labels or namespaces.

More Details: kubectl delete

Imperative

Delete Ingress By Name

kubectl delete ingress [INGRESS NAME] -n [NAMESPACE]

Delete Ingress By Label

kubectl delete ingress -l name=[LABEL] -n [NAMESPACE]

Delete All Ingress in Namespace

kubectl delete ingress -n [NAMESPACE] --all

Declarative

kubectl delete -f [INGRESS TEMPLATE].yaml

<< Kubernetes Services | Kubernetes Ingress | Kubernetes ConfigMaps and Secrets >>

Marcin Narloch

Marcin Narloch

Creative and out-of-the-box thinker with strong interests and knowledge in technology and innovation.
Docker Building Blocks Previous post Kubernetes ConfigMaps and Secrets
Docker Building Blocks Next post Kubernetes Services

Leave a Reply

Your email address will not be published.