Service 引入主要是解决 Pod 的动态变化,提供统一访问入口:
- 防止 Pod 失联,准备找到提供同一个服务的 Pod (服务发现)
- 定义一组 Pod 的访问策略 (负载均衡)
kubectl apply -f deploy.yaml apiVersion: apps/v1kind: Deploymentmetadata:name: chiyi-nginxspec:replicas: 3selector:matchLabels:app: chiyi-nginxtemplate:metadata:labels:app: chiyi-nginxspec:containers:- name: nginximage: nginx:1.14.2ports:- containerPort: 80 部署 service kubectl apply -f service.yaml apiVersion: v1kind: Servicemetadata:name: chiyi-nginxspec:selector:app: chiyi-nginxports:- protocol: TCPport: 80targetPort: 80nodePort: 30002type: NodePort 查看 service 和 pod 的关系 kubectlget epcurl 10.244.1.58:80 说明:Service 通过标签关联一组 Pod
Service 为一组 Pod 提供负载均衡能力
[root@k8s-master service]# kubectl get epNAMEENDPOINTSAGEchiyi-nginx10.244.1.58:80,10.244.1.59:80,10.244.2.46:805m19skubernetes172.17.28.225:644323h[root@k8s-master service]# curl 10.244.1.58:80Welcome to nginx!body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}Welcome to nginx!If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer tonginx.org.
Commercial support is available atnginx.com.
- 春季老年人吃什么养肝?土豆、米饭换着吃
- 三八妇女节节日祝福分享 三八妇女节节日语录
- 老人谨慎!选好你的“第三只脚”
- 校方进行了深刻的反思 青岛一大学生坠亡校方整改校规
- 脸皮厚的人长寿!有这特征的老人最长寿
- 长寿秘诀:记住这10大妙招 100%增寿
- 春季老年人心血管病高发 3条保命要诀
- 眼睛花不花要看四十八 老年人怎样延缓老花眼
- 香槟然能防治老年痴呆症? 一天三杯它人到90不痴呆
- 老人手抖的原因 为什么老人手会抖
