需要第一个服务的IP地址的服务的部署

时间:2019-05-03 15:34:08

标签: kubernetes kubectl kubernetes-pod

我已经创建了两个服务。

myymlservice

mysql部署

myymlservice需要mysql-deployment的负载平衡器的IP地址(以便它可以为其创建连接字符串)

 minikube service list

|-------------|----------------------|--------------------------------|
|  NAMESPACE  |         NAME         |              URL               |
|-------------|----------------------|--------------------------------|
| default     | kubernetes           | No node port                   |
| default     | mysql-deployment     | http://192.168.99.100:30928    |
| default     | myymlservice         | http://192.168.99.100:32724    |
|             |                      | http://192.168.99.100:31461    |
| kube-system | kube-dns             | No node port                   |
| kube-system | kubernetes-dashboard | No node port                   |
|-------------|----------------------|--------------------------------|

..

kubectl describe service mysql-deployment
Name:                     mysql-deployment
Namespace:                default
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"mysql-deployment","namespace":"default"},"spec":{"ports":[{"port":1433,"protoc...
Selector:                 app=mysql
Type:                     LoadBalancer
IP:                       10.107.53.255
Port:                     <unset>  1433/TCP
TargetPort:               1433/TCP
NodePort:                 <unset>  30928/TCP
Endpoints:                172.17.0.7:1433
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

一项服务(或支持该服务的容器)如何(使用yml)获得IP地址?

关于上一个问题的更多设置:

single service with multiple exposed ports on a pod with multiple containers

1 个答案:

答案 0 :(得分:1)

如果要构建连接字符串,可以使用服务名称代替ip。例如mysql-deployment.default.svc.cluster.local。这是因为kubernetes具有一个“ dns” built-indns resolution