First of all, we already have a mysql pod container (workload) Kubesphere system will deploy a service for our system by default, we can delete this service first (do not delete the corresponding workload), and then recreate our service. When creating, we need to select Create a service based on a particular workload. We first create workloads based on mysql's internal network. Then we select the corresponding stateful replica set (mysql) and set the corresponding service information we need.
Since it is internal network access, we do not need to set the corresponding ip information, we can choose the internal domain name to set our network situation, and set 3306 as our port mapping (mapping to the pod container).
Then we only need to keep clicking next until the services are created successfully, and we can see the following page. According to the dns information in the left menu bar, we enter the pod and use the mysql-server-in.his in the dns information to connect to the mysql service.
The specific commands are as follows:
Mysql -h mysql-server-in.his -u root -p
We can see that we can directly access network resources through the pod of the internal network according to the dns information of the service.
Next we need to configure the extranet
Still create a specified workload in services. .
To expose specific port information, select a specific workload, and select the virtual ip address mode, we need to map the virtual ip address to access the pod container from the external network.
Among them, we need to set the mode to node port mode.
When the container is created, we can see that there is one more component information in our service list
We can see that our port 3306 can be mapped to port 31565, and we try to access port 31565 of our server through the external network.
We can see that our network can be accessed normally.
Therefore, the mapping of the internal container pod to the external network can be realized through the configuration of the server.