KubernetesUpAndRunning-Services
来源:互联网 发布:债市与股市的关系 知乎 编辑:程序博客网 时间:2024/06/06 12:18
Service discovery
is a mechanism that enables clients of a service to locate service endpoints without manual intervention. DNS
is the most common implementation of service discovery in use today.
Kubernetes provides service discovery out of the box in the form of an Endpoints API, DNS, and environment variables which can be exposed to Pods. Each service discovery mechanism is backed by Kubernetes Services and Endpoints.
Endpoints
Endpoints hold a collection of IP addresses and ports that back a Kubernetes Service.The following Kubernetes configuration represents an Endpoint for the “my-service” Service with a single service endpoint at 10.52.0.2 on port 80:
apiVersion: v1kind: Endpointsmetadata: name: my-service namespace: defaultsubsets: - addresses: - ip: 10.52.0.2 ports: - port: 80
Virtual IPs and Service Proxies
When Services are created via the Kubernetes API, a virtual IP address is allocated to the Service from the Kubernetes Service address range. One thing to keep in mind Virtual IP addresses are not assigned to any network interfaces on the hosts or Pods. Virtual IP addresses must be routed in order to work.
Creating Services
apiVersion: v1kind: Servicemetadata: labels: app: helloworld name: helloworldspec: ports: - port: 80 protocol: TCP targetPort: 80 selector: app: helloworld
Submit the helloworld service to the Kubernetes API using the kubectl create command:
$ kubectl create -f helloworld.yamlservice "helloworld" created
Managing Services
$ kubectl get servicesNAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGEhelloworld 10.223.244.100 <none> 80/TCP app=helloworld 20skubernetes 10.223.240.1 <none> 443/TCP <none> 9m$ kubectl describe services helloworldName: helloworldNamespace: defaultLabels: app=helloworldSelector: app=helloworldType: ClusterIPIP: 10.223.244.100Port: <unnamed> 80/TCPEndpoints: <none>Session Affinity: NoneNo events.
Use the spec.clusterIP
key to assign a fixed cluster IP to the helloworld service.
apiVersion: v1kind: Servicemetadata: labels: app: helloworld name: helloworldspec: clusterIP: 10.223.244.110 ports: - port: 80 protocol: TCP targetPort: 80 selector: app: helloworld
$ kubectl delete services helloworld$ kubectl create -f helloworld.yamlName: helloworldNamespace: defaultLabels: app=helloworldSelector: app=helloworldType: ClusterIPIP: 10.223.244.110Port: <unnamed> 80/TCPEndpoints: <none>Session Affinity: NoneNo events.
Service Discovery
Environment variables
Environment variables are created for every service defined. These variables are made available to every pod in the namespace.
Environment variables are not dynamically updated.
DNS
Due to these shortcomings, DNS is the preferred way to communicate information about Services.
In most Kubernetes deployments Services will be mapped to DNS names using the skyDNS cluster add-on
.
Exposing Services
- NodePort
- LoadBalancer
- External IPs
- KubernetesUpAndRunning-Services
- KubernetesUpAndRunning-Introduction
- KubernetesUpAndRunning-Containers
- KubernetesUpAndRunning-Pods
- KubernetesUpAndRunning-Deploying Kubernetes
- KubernetesUpAndRunning-Labels and Annotations
- Services
- services
- Services
- services
- Services
- Services
- Services
- Services
- Services
- Services
- Services
- Services
- TODO:火热的集福,我这样看
- 收集了很多音乐播放器类的Android项目源码,非常不错的开源项目【转】
- Hive权限控制和超级管理员的实现
- Android Recovery UI
- 你好!世界!
- KubernetesUpAndRunning-Services
- 常用正则表达式和JS控制输入框输入限制(数字、汉字、字符)
- printf格式控制(转)
- iOS设计模式-装饰模式
- Unity结合C++开发服务器实现多人游戏(二)
- The Architecture of the Java Virtual Machine(2)
- Javascript模块化编程(三):require.js的用法
- 入门1-相关须知
- 中望CAD快捷键