Kubernetes-Endpoint外部サービスへのアクセス
3776 ワード
k 8 sがクラスタ外の独立したサービスにアクセスする最も良い方法は、mysqlサービスを例に挙げるEndpoint方式を採用することである. mysql-serviceを作成します.yaml mysql-endpointsを作成する.yaml 接続データベース のテストこのサービス を表示
apiVersion: v1
kind: Service
metadata:
name: mysql-production
spec:
ports:
- port: 3306
kind: Endpoints
apiVersion: v1
metadata:
name: mysql-production
namespace: default
subsets:
- addresses:
- ip: 192.168.1.25
ports:
- port: 3306
[root@k8s-master endpoint]# kubectl exec -it mysql-client-j3fr3 bash
bash-4.1# mysql -hmysql-production -u user -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 496257557
Server version: 5.5.52-MariaDB-1ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
[root@k8s-master endpoint]# kubectl describe svc mysql-production
Name: mysql-production
Namespace: default
Labels:
Annotations:
Selector:
Type: ClusterIP
IP: 10.254.218.165
Port: 3306/TCP
Endpoints: 192.168.1.25:3306
Session Affinity: None
Events: