In Deploy a Spring Boot Application into minikube with Command ,We deploy an application for Spring Boot app into minikube, and in this article we will expose the application through ingress for user access outside of the minikube (cluster).
Install Ingress
In minikube, Ingress is an addons. So let’s first look at those addons in the current minikube。 Execute:
1 | minikube addons list |
The system display:
1 | |-----------------------------|----------|--------------| |
As you can see, the current ingress is in the disabled state. Execute the enable command to activate it。
1 | minikube addons enable ingress |
You will be prompted immediately:
1 | * The 'ingress' addon is enabled |
But in fact, ingress can not be used immediately, because ingress is actually built as a system POD, it also needs to download its own image. We can execute the get pods command to see if it is already set up:
1 | kubectl get pods -n kube-system |
The above command list the all pods in kube-system (system namesapce). The result is similar:
1 | NAME READY STATUS RESTARTS AGE |
If nginx-ingress-controller-xxxx is already in the Running state, activation of ingress has been completed.
Execute ‘addons list’ again,
1 | minikube addons list |
You can see,
1 | |-----------------------------|----------|--------------| |
The ingress has been activated。
Add an Ingress rule
The previous operation just activates ingress, to use ingress to expose the service, you also need to customize the rules of ingress。 Create a new file and name it: k8s-basic-ingress.yaml:
1 | apiVersion: networking.k8s.io/v1beta1 |
Note: Host must use a DNS name, not an IP address
In this rule definition, we do not define the port of ingress, and the system uses the default port: 80
Deploy this rule, execute:
1 | kubectl apply -f .\k8s-basic-ingress.yaml |
The system display:
1 | ingress.networking.k8s.io/k8s-basic-ingress created |
We can view the ingress that have been deployed in the current minikube, execute:
1 | kubectl get ingress |
The system display:
1 | NAME HOSTS ADDRESS PORTS AGE |
As you can see, the ingress rule for k8s-basic-ingress has been successfully deployed.
Because we use a custom minikube.study.me as the domain name, which doesn’t exist in the DNS system, we need to manually add the host record. Edit the native hosts file, which is located in the window system:
1 | C:\Windows\System32\drivers\etc |
在文件末尾添加一行:
1 | 192.168.1.54 minikube.study.me |
192.168.1.54 is the IP address of the host on which minikube is running。
It can then be accessed in a browser:
1 | http://minikube.study.me |