In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shares with you how to understand the three IP address types of Kubernetes. Xiaobian thinks it is quite practical, so share it with you. I hope you can gain something after reading this article. Let's not say much. Let's take a look at it together with Xiaobian.
Many Kubernetes beginners don't understand the three different IP addresses and working mechanisms in Kubernetes very well.
Let's learn from the simplest example.
Create an nginx based deployment using the following command line:
kubectl run nginx --image=nginx:maxline
Use kubectl get deploy to view successfully generated deployments named nginx:
At this point, the nginx pod in this deployment cannot provide services to the outside world.
We create a service that the outside world can consume. Use the command line to create such a service:
kubectl expose deployment nginx --type=LoadBalancer --port=80 --target-port=80
The type of type is selected as LoadBalancer, --port is specified as port 80, which means that the service port exposed to the outside world is 80, --target-port=80, this port is the working port of the nginx docker container inside the pod, and the default is 80. In fact, a mapping relationship between port 80 developed to the outside world and the internal port of the nginx container is established here.
After execution, we call the following command line and see the Cluster IP and External IP of the created service.
The external IP is well understood, and this service provides services to the outside world through the external IP plus the mapping to port 80 that we introduced earlier:
Enter External IP http://35.241.173.27:80 in your browser to successfully access the index.html of the nginx server:
However, we cannot access the functionality provided by this Service through the Cluster IP of the Service.
We know that all pods in Kubernetes can communicate with each other without having to go through Network Address Translation-NAT, and all nodes can communicate with all pods. The Cluster IP of Service is an internal IP address dedicated to communicating with nodes or pods within the Cluster. Communicate with the outside world, or through External IP.
NodePort
Try NodePort again.
kubectl expose deployment nginx --type=NodePort --port=80 --target-port=80
Note that the port type of NodePort displayed below the PORT column in the figure below: 31375
This port number is automatically generated by the Kubernetes expose command and ranges from 30000 to 32767. If you need to modify, you can edit the api server configuration file: /etc/kubernetes/apiserver:
With this port number, we can use the IP address of a node at random, followed by the concatenation:31375, which is the complete address that can be consumed externally.
Use kubectl get nodes -o wide, select External-IP of any node in the result, followed by:31375:
Testing:
http://146.148.23.183:31375/
The test passed.
Port forwarding function of Pod
It is worth mentioning that sometimes we need a simple way to see if a pod is working properly for testing purposes. It would be too much trouble to create a service every time by kubectl.
Here's a simple solution: pod port forward.
For example, we want to test the function of the first pod returned by get pods in the following figure, named nginx-6f754dd4b9-74jdn:
Execute command line kubectl port-forward pod/nginx-6f754dd4b9-74jdn 8080:80
Forwarding from 127.0.0.1: 8080-> 80, which means mapping port 8080 of the current host to working port 80 of the nginx pod:
Finally, you can directly access the services provided by nginx pod through localhost:8080:
The above is how to understand the three IP address types of Kubernetes, Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.