Service有userspace、iptables、ipvs三种工作模式,可在配置文件/etc/sysconfig/kubelet中添加配置参数KUBE_PROXY_MODE=ipvs来改变kubernetes的工作模式(后续版本版本此配置路径可能发生更改,可以用rpm -ql kubelet来查看配置文件路径);ExternalName, ClusterIP, NodePort, and LoadBalancer五种service类型type,默认为ClusterIP;port、targetPort、nodePort三种端口选项,若使用NodePort类型,使用nodePort才生效。

实例:

apiVersion: v1

kind: Service

metadata:

name: redis

namespace: default

spec:

selector:

app: redis

role: logstor

clusterIP: 10.97.97.97

type: ClusterIP

ports:

- port: 6379

targetPort: 6379

默认clusterIP系统会自动分配,为了不造成IP冲突可以不指定,让系统自动分配;如果clusterIP设置为None,即没有service IP地址,直接调用pod的IP地址。

service配置清单spec主要包含如下选项:

[root@master1 yaml]# kubectl explain service.spec

KIND: Service

VERSION: v1

RESOURCE: spec

DESCRIPTION:

Spec defines the behavior of a service.

https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

ServiceSpec describes the attributes that a user creates on a service.

FIELDS:

clusterIP

clusterIP is the IP address of the service and is usually assigned randomly

by the master. If an address is specified manually and is not in use by

others, it will be allocated to the service; otherwise, creation of the

service will fail. This field can not be changed through updates. Valid

values are "None", empty string (""), or a valid IP address. "None" can be

specified for headless services when proxying is not required. Only applies

to types ClusterIP, NodePort, and LoadBalancer. Ignored if type is

ExternalName. More info:

https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies

externalIPs

externalIPs is a list of IP addresses for which nodes in the cluster will

also accept traffic for this service. These IPs are not managed by

Kubernetes. The user is responsible for ensuring that traffic arrives at a

node with this IP. A common example is external load-balancers that are not

part of the Kubernetes system.

externalName

externalName is the external reference that kubedns or equivalent will

return as a CNAME record for this service. No proxying will be involved.

Must be a valid RFC-1123 hostname (https://tools.ietf.org/html/rfc1123) and

requires Type to be ExternalName.

externalTrafficPolicy

externalTrafficPolicy denotes if this Service desires to route external

traffic to node-local or cluster-wide endpoints. "Local" preserves the

client source IP and avoids a second hop for LoadBalancer and Nodeport type

services, but risks potentially imbalanced traffic spreading. "Cluster"

obscures the client source IP and may cause a second hop to another node,

but should have good overall load-spreading.

healthCheckNodePort

healthCheckNodePort specifies the healthcheck nodePort for the service. If

not specified, HealthCheckNodePort is created by the service api backend

with the allocated nodePort. Will use user-specified nodePort value if

specified by the client. Only effects when Type is set to LoadBalancer and

ExternalTrafficPolicy is set to Local.

ipFamily

ipFamily specifies whether this Service has a preference for a particular

IP family (e.g. IPv4 vs. IPv6). If a specific IP family is requested, the

clusterIP field will be allocated from that family, if it is available in

the cluster. If no IP family is requested, the cluster's primary IP family

will be used. Other IP fields (loadBalancerIP, loadBalancerSourceRanges,

externalIPs) and controllers which allocate external load-balancers should

use the same IP family. Endpoints for this Service will be of this family.

This field is immutable after creation. Assigning a ServiceIPFamily not

available in the cluster (e.g. IPv6 in IPv4 only cluster) is an error

condition and will fail during clusterIP assignment.

loadBalancerIP

Only applies to Service Type: LoadBalancer LoadBalancer will get created

with the IP specified in this field. This feature depends on whether the

underlying cloud-provider supports specifying the loadBalancerIP when a

load balancer is created. This field will be ignored if the cloud-provider

does not support the feature.

loadBalancerSourceRanges

If specified and supported by the platform, this will restrict traffic

through the cloud-provider load-balancer will be restricted to the

specified client IPs. This field will be ignored if the cloud-provider does

not support the feature." More info:

https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/

ports

The list of ports that are exposed by this service. More info:

https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies

publishNotReadyAddresses

publishNotReadyAddresses, when set to true, indicates that DNS

implementations must publish the notReadyAddresses of subsets for the

Endpoints associated with the Service. The default value is false. The

primary use case for setting this field is to use a StatefulSet's Headless

Service to propagate SRV records for its Pods without respect to their

readiness for purpose of peer discovery.

selector

Route service traffic to pods with label keys and values matching this

selector. If empty or not present, the service is assumed to have an

external process managing its endpoints, which Kubernetes will not modify.

Only applies to types ClusterIP, NodePort, and LoadBalancer. Ignored if

type is ExternalName. More info:

https://kubernetes.io/docs/concepts/services-networking/service/

sessionAffinity

Supports "ClientIP" and "None". Used to maintain session affinity. Enable

client IP based session affinity. Must be ClientIP or None. Defaults to

None. More info:

https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies

sessionAffinityConfig

sessionAffinityConfig contains the configurations of session affinity.

topologyKeys

topologyKeys is a preference-order list of topology keys which

implementations of services should use to preferentially sort endpoints

when accessing this Service, it can not be used at the same time as

externalTrafficPolicy=Local. Topology keys must be valid label keys and at

most 16 keys may be specified. Endpoints are chosen based on the first

topology key with available backends. If this field is specified and all

entries have no backends that match the topology of the client, the service

has no backends for that client and connections should fail. The special

value "*" may be used to mean "any topology". This catch-all value, if

used, only makes sense as the last value in the list. If this is not

specified or empty, no topology constraints will be applied.

type

type determines how the Service is exposed. Defaults to ClusterIP. Valid

options are ExternalName, ClusterIP, NodePort, and LoadBalancer.

"ExternalName" maps to the specified externalName. "ClusterIP" allocates a

cluster-internal IP address for load-balancing to endpoints. Endpoints are

determined by the selector or if that is not specified, by manual

construction of an Endpoints object. If clusterIP is "None", no virtual IP

is allocated and the endpoints are published as a set of endpoints rather

than a stable IP. "NodePort" builds on ClusterIP and allocates a port on

every node which routes to the clusterIP. "LoadBalancer" builds on NodePort

and creates an external load-balancer (if supported in the current cloud)

which routes to the clusterIP. More info:

https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types

kubectl patch svc myapp -p ‘{“spec”:{“sessionAffinity”:”ClientIP”}}’: 打补丁设置sessionAffinity为ClientIP后 ,是pod资源仅运行在某个node上面

service mysql k8s_Kubernetes/K8S基础使用方法总结【五】——Service相关推荐

  1. service mysql k8s_Kubernetes(k8s)中文文档 名词解释 Services_Kubernetes中文社区

    Overview(概述) Kubernetes Pod是平凡的,它门会被创建,也会死掉(生老病死),并且他们是不可复活的. ReplicationControllers动态的创建和销毁Pods(比如规 ...

  2. k8s service type_通过搭建MySQL掌握k8s(Kubernetes)重要概念(上):网络与持久卷...

    点击上方蓝色"Go语言中文网"关注我们,设个星标,每天学习 Go 语言 前一篇"通过实例快速掌握 k8s(Kubernetes)核心概念[1]"讲解了 k8s ...

  3. mysql安装服务和安装中常见问题install/Remove of the Service Denied与net start mysql服务启动失败解决方法

    mysql安装服务和安装中常见问题install/Remove of the Service Denied与net start mysql服务启动失败解决方法 参考文章: (1)mysql安装服务和安 ...

  4. ASP.NET Core on K8S深入学习(1)K8S基础知识与集群搭建

    在上一个小系列文章<ASP.NET Core on K8S学习初探>中,通过在Windows上通过Docker for Windows搭建了一个单节点的K8S环境,并初步尝试将ASP.NE ...

  5. mysql8.0 服务移除_Linux下彻底删除Mysql 8.0服务的方法

    观看本文前最好有一定的Linux命令基础,具体为centos7.3环境中清除使用yum安装的Mysql 卸载前请先关闭Mysql服务 service mysql stop 使用 rpm 命令的方式查看 ...

  6. mysql上k8s_通过搭建MySQL掌握k8s(Kubernetes)重要概念(上):网络与持久卷

    上一篇"通过实例快速掌握k8s(Kubernetes)核心概念"讲解了k8s的核心概念,有了核心概念整个骨架就完整了,应付无状态程序已经够了,但还不够丰满.应用程序分成两种,无状态 ...

  7. MYSQL的安装基础语法笔记

    MYSQL基础语法 学习目标 能够理解数据库的概念(知道数据库是用来干嘛的) 能够安装MySQL数据库 能够启动,关闭及登录MySQL 能够使用SQL语句操作数据库(创建.删除.修改.查询数据库) 能 ...

  8. 【云原生之k8s】k8s基础详解

    [云原生之k8s]k8s基础详解 前言 一.kubernetes介绍 (1)kubernetes简介 (2)应用部署方式的演变 二.kubernetes组件 (1)kubernetes架构 (2)ma ...

  9. K8s基础知识学习笔记及部分源码剖析

    K8s基础知识学习笔记及部分源码剖析 在学习b站黑马k8s视频资料的基础上,查阅了配套基础知识笔记和源码剖析,仅作个人学习和回顾使用. 参考资料: 概念 | Kubernetes 四层.七层负载均衡的 ...

最新文章

  1. 【转】GeoServer地图开发解决方案(四):发布Web地图服务(WMS)篇
  2. 微软私有云分享(R2)7-Linux虚拟机无DNS?
  3. 某一个接口403 其他接口可以调通_设计模式HR:不会设计模式,你来面什么试?你以为设计模式只有23种?(真正的入门到精通可以用到入土)...
  4. Spring------自动化装配Bean(一)
  5. qc中的流程图怎么画_QC流程图参考
  6. 在HTML中使用WCF RESTful上传文件
  7. 使用PowerShell创建Azure Storage的SAS Token访问Azure Blob文件
  8. hive udf开发超详细手把手教程
  9. Rational Rose概述
  10. DataWhale第21期组队学习自然语言处理实践(知识图谱)task4— 用户输入->知识库的查询语句
  11. java 实现ps功能_JS实现在线ps功能详解
  12. 笔记本电脑触控板失灵解决办法
  13. PreTranslateMessage详解
  14. 零基础,没方向,如何快速有效学习编程语言?
  15. KANKAN AI不良信息过滤技术:用数据证明自己是最好的
  16. 杭州美图JAVA面试(美图美妆app组)
  17. linux群晖系统密码忘记,【系统篇】猫盘群晖重置密码、重装、重置、升级与降级等...
  18. 英语语法最终珍藏版笔记-14独立主格结构
  19. zabbix解决监控图表中文乱码问题
  20. EA公司CFO简森将于月底离职

热门文章

  1. jmeter5.4.1 调整默认工具栏图片大小
  2. 批处理bat一键安装APK
  3. iPerf 3.13 的交叉编译,移植,使用
  4. 查询彩票中奖号码小程序
  5. 分享微信公众号留言评论功能开通方法
  6. 单点登录涉及的技术点
  7. ORB_SLAM2新增稠密建图代码笔记
  8. 【hexo】基础教程-三-添加网易云音乐
  9. 计算机专业不会编程怎么找工作?
  10. 海康威视SDK登录失败,错误码为8