Get the App
SLTechnology News&Howtos  ›  Servers  › 

Endpoints of Kubernetes

Shulou Source: shulou.com Published: 2022-06-02 13:41:15 09月23日 Update

In the previous blog post, we demonstrated how to achieve persistent storage of kubernetes through ceph so that stateful services like mysql can run and save data in kubernetes. This looks wonderful, but in the actual production environment, the performance problems of disks implemented through distributed storage will be very prominent in IO-intensive applications such as mysql. Therefore, in practical applications, applications such as mysql will not be managed directly in kubernetes, but will be deployed independently with dedicated servers. Stateless applications like web will still run in kubernetes. At this time, there are two ways for web servers to connect to databases other than kubernetes management: one is to directly connect to the physical server IP where the database is located, and the other is to directly map the external server to a service within kubernetes with the help of kubernetes's Endpoints.

Let's look at a simple example:

ApiVersion: v1kind: Servicemetadata: name: plat-devspec: ports:-port: 3306 protocol: TCP targetPort: 3306---apiVersion: v1kind: Endpointsmetadata: name: plat-devsubsets:-addresses:-ip: "10.5.10.109" ports:-port: 3306

This example defines two kinds of resource objects, Service and Endpoints. The definition of Service does not use a tag selector, but an Endpoints with the same name as Service is defined later, so that they can be associated automatically. The subsets of Endpoints specifies the IP and port of the external server to which you need to connect.

We can look at it through kubectl get svc:

[root@server--IP EXTERNAL--dev. /

We can start another sample container and do the following in the container to try to connect to the external service:

[root@server-116 test] # kubectl exec-it nginx / bin/bash [root@nginx nginx] # nslookup plat-devServer: 10.254.0.100Address: 10.254.0.100#53Name: plat-dev.default.svc.cluster.localAddress: 10.254.4.76 [root@nginx nginx] # mysql-uxxx-pxxx-hplat-devWelcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 349446Server version: 5.6.14 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > show databases

Tags: Services servers applications data examples actual containers databases methods state storage management running wonderful middle finger distributed can pass objects that is performance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info Microsoft MariaDB Apple