分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

Kubernetes Headless Service

发布时间:2023-09-06 02:14责任编辑:白小东关键词:暂无标签

1. Headless Service

headless service 需要将 spec.clusterIP 设置成 None。

因为没有ClusterIP,kube-proxy 并不处理此类服务,因为没有load balancing或 proxy 代理设置,在访问服务的时候回返回后端的全部的Pods IP地址,主要用于开发者自己根据pods进行负载均衡器的开发(设置了selector) 或 StatefulSet.

2. Test Headless Service With selectors

$cat deployment.yamlapiVersion: extensions/v1beta1kind: Deploymentmetadata: ?name: nginx-deploymentspec: ?replicas: 2 # tells deployment to run 2 pods matching the template ?template: # create pods using pod definition in this template ???metadata: ?????# unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is ?????# generated from the deployment name ?????labels: ???????app: nginx_test ???spec: ?????containers: ?????- name: nginx ???????image: nginx:1.7.9 ???????ports: ???????- containerPort: 80
$ cat headless_service.yamlkind: ServiceapiVersion: v1metadata: ?name: nginx-servicespec: ?selector: ???app: nginx_test ?ports: ???- protocol: TCP ?????port: 80 ?????targetPort: 80 ?clusterIP: None

通过dns访问,会返回后端pods的列表

登录到Cluster的内部pod

nslookup nginx-servicenslookup: can‘t resolve ‘(null)‘: Name does not resolveName: ?????nginx-serviceAddress 1: 10.10.23.36Address 2: 10.10.23.39

Kubernetes Headless Service

原文地址:https://www.cnblogs.com/vincenshen/p/9642156.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved