backgroundTechnology, life, opinions, originality. Original public account; mainly focusing on Go, JVM, concurrency, distribution, network and other related technologies. In the first two chapters, we deployed the application to k8s. At the same time, different services can also be called through service. Now there is another step to expose our application to the public network and provide domain name access. This step is similar to our previous configuration of Nginx and binding domain name. The service that provides this capability is called Ingress in k8s. From this description, we can actually see that Ingress is more of an operation and maintenance job, but it does not prevent us as developers from understanding this part of the content; understanding how the entire system works is also a skill that developers should master. Install Ingress ControllerBefore officially using Ingress, you need to install an Ingress controller for k8s. Here we install the official Ingress-nginx controller. Of course, there are also various controllers provided by the community or enterprises: picture There are two ways to install: helm or directly apply a resource file. We will explain helm separately in the following chapters. Here you can just use the resource file to install it. I have uploaded it to GitHub and can access it here: https://github.com/crossoverJie/k8s-combat/blob/main/deployment/ingress-nginx.yaml In fact, this file is also copied directly from the official one, and you can also install it directly using this path:
However, please note that after installation, the container status may remain in the Pending state. When viewing the container events, you will find that the image pull failed.
In the yaml file just now, you can see that there are several images that need to be pulled. We can first manually pull the images locally: picture If you still cannot pull, you can try to configure several domestic mirror sources to pull images: picture I use the k8s that comes with docker-desktop here, and I recommend readers to use this tool as well. Create IngressAfter the installation is successful using the yaml just now, a Pod will be created in the ingress-nginx namespace. If the status is Running through the get command, the installation is successful.
After that, you can create the Ingress resource: It is easy to understand this content. An Ingress object is created, and the key point is how the rules are defined here.
The ingressClassName: nginx here is also the name defined in the controller that was just installed, defined by this resource. Our rule is very simple, which is to route two different domain names to two different services.
testAlso to facilitate testing, I added a new interface in the application image to return the hostname of the current Pod. Since I don’t actually have the two domain names www.service1.io/www.service2.io, I can only configure the host locally for simulation.
When we repeatedly request this interface twice, we will get two different hostnames, which means that our request is loaded in a round-robin manner on the two Pods proxied by these two services. We can also use describe directly to view our ingress definition and routing rules: picture If we manually add a new domain name resolution: It will directly return 404 because no rules for this domain name were found. Access Principlepicture The entire request path is shown in the figure above. In fact, our Ingress is essentially a service (so it can also start multiple copies to carry out load), but its type is LoadBalancer. Usually this type of service will be bound to an external IP by the cloud vendor, so that the Ingress can be accessed through this external IP. The service of our application is ClusterIP, which can only be accessed within the application. picture From the service information, we can also see that the external IP bound to our ingress service is localhost (local reason). SummarizeIngress usually acts as a gateway. Later, when we use Istio, we can also use the controller provided by Istio to replace Ingress-nginx, which can more conveniently manage internal and external network traffic. All source code of this article can be accessed here: https://github.com/crossoverJie/k8s-combat |
>>: Shen Bin from CAICT: 5G factories promote high-quality development of "5G+Industrial Internet"
At the "Optical Connection of Everything, In...
As more and more people use the internet, the amo...
British telecom operator Virgin Media O2 (VMO2) h...
[51CTO.com original article] From October 20 to 2...
[[353172]] This article is reprinted from the WeC...
This morning, the Ministry of Industry and Inform...
introduce DDoS is the abbreviation of Distributed...
Today, RackNerd offers three hot-selling packages...
[51CTO.com original article] At the end of May, t...
HTTP 1.0 was released in 1996, laying the foundat...
LOCVPS (Global Cloud) launched its first promotio...
After the rapid development in 2020, 2021 is a cr...
For the younger generation, they are born in a ma...
What can 5G do? This is a question that everyone ...
Just like decoration in life, during the decorati...