This blog will demonstrate:
- Prerequisite: Deploy Ingress Controller and Create Ingress in Kubernetes
- How to Get Ingress Using “kubectl get”?
- How to Get and Save Ingress in Yaml Using “kubectl get ingress”?
- How to Describe Ingress in Kubernetes?
- Conclusion
Prerequisite: Deploy Ingress Controller and Create Ingress in Kubernetes
The ingress resource (yaml) file is managed and operated through the Ingress controller. To start using ingress to route the application traffic, the user must need to deploy the ingress controller in the Kubernetes cluster. After that, the user can create the new ingress in Kubernetes by applying the Ingress resource yaml file or using the “kubectl create” command.
After deploying the Ingress controller and creating the ingress, the user can access the Kubernetes ingress using the “kubectl get ingress” command. To deploy the ingress controller and to create and use the ingress, follow our associated “Deploy ingress controller in Kubernetes” and “Create Ingress in Kubernetes” articles respectively.
How to Get Ingress Using “kubectl get”?
To get the Ingress in Kubernetes, follow the below steps.
Step 1: Launch PowerShell
First, launch the Windows PowerShell with administrator rights. Administrative privileges are required to run the minikube cluster on Windows built-in Hyper-V:
Step 2: Start Kubernetes Cluster
Next, start the Kubernetes cluster using the “minikube start” command:
Step 3: Get Ingress
To get all the resources of Kubernetes, the user usually uses the “kubectl get all” command. But this command does not contain the information about Kubernetes ingress and egress:
This will only display the “Pods”, “Deployments”, “ReplicaSet”, and “Services”:
In order to access the Kubernetes ingress, either use the “kubectl get in” or “kubectl get ingress” command:
Here, you can see currently we have only one ingress named “demo-ingress”:
How to Get and Save Ingress in Yaml Using “kubectl get ingress”?
Sometimes, users want to access the ingress details along with their configurations and routing rules. To do so, they can access the ingress in a user-defined format through a given command. Here, “-o” is used to specify the output format:
Here, you can see that the user can view the routing rules that are defined in “demo-ingress”:
To save the ingress configuration and routing rules in a new file, use the below command. After the “>” operator, set the file name in which you want to store the ingress data and routing rules:
This command is also helpful for creating the backup of ingress:
For verification, list down the current directory files using the “ls” command:
Here, you can see we have successfully saved the output of the “kubectl get ingress” command in the “new-ingress.yml” file:
How to Describe Ingress in Kubernetes?
Sometimes the user may forget the routing path or rule that is defined in the Ingress resource or may want to inspect the ingress in detail. For this purpose, they can describe the ingress using the “kubectl describe ingress <ingress-name>” command:
That is all about getting ingress using the “kubectl get ingress” command.
Conclusion
To get ingress in Kubernetes, first, deploy the Ingress controller and create an ingress. After that, access the Kubernetes ingress using the “kubectl get ingress” command. To access the ingress details and routing rules in Yaml format, use the “kubectl get ingress <ingress-name> -o yaml” command. To describe or inspect the ingress, use the “kubectl describe ingress <ingress-name>” command. We have demonstrated how to get Kubernetes ingress using the “kubectl get ingress” command.