【kubernetes/k8s概念】kube-apiserver启动参数

kubernetes 1.12.1版本

DESC

The Kubernetes API server validates and configures data for the api objects which include pods, services, replicationcontrollers, and others. The API Server services REST operations and provides the frontend to the
cluster's shared state through which all other components interact.

 

kube-apiserver启动命令

/opt/k8s/bin/kube-apiserver

  --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota

  --advertise-address=192.168.74.57

  --bind-address=0.0.0.0

  --insecure-bind-address=127.0.0.1

  --authorization-mode=Node,RBAC

  --kubelet-https=true

  --token-auth-file=/etc/kubernetes/token.csv

  --service-cluster-ip-range=10.200.0.0/16

  --service-node-port-range=6000-52766

  --tls-cert-file=/etc/kubernetes/ssl/kubernetes.pem

  --tls-private-key-file=/etc/kubernetes/ssl/kubernetes-key.pem

  --client-ca-file=/etc/kubernetes/ssl/ca.pem

  --service-account-key-file=/etc/kubernetes/ssl/ca-key.pem

  --etcd-servers=http://127.0.0.1:2379

  --enable-swagger-ui=true

  --allow-privileged=true

  --apiserver-count=2

  --audit-log-maxage=30

  --audit-log-maxbackup=3

  --audit-log-maxsize=100

  --audit-log-path=/var/lib/audit.log

  --event-ttl=1h

  --logtostderr=true --v=2

 

kube-apiserver启动基本参数详解

 

Generic flags:

参数 

描述

--advertise-address

向集群成员发布apiserver的IP地址,该地址必须能够被集群的成员访问。如果为空,则使用 --bind-address,如果 --bind-address未指定,那么使用主机的默认接口。

--authorization-mode

在安全端口上执行授权的有序的插件列表。默认值:AlwaysAllow

以逗号分隔的列表:AlwaysAllow,AlwaysDeny,ABAC,Webhook,RBAC,Node.

 

Etcd flags

参数 

描述

--etcd-cafile保护etcd通信的SSL证书颁发机构文件
--etcd-certfile用于保护etcd通信的SSL证书文件
--etcd-keyfile用来保护etcd通信的SSL key文件
--etcd-serversetcd服务器列表(格式://ip:port),逗号分隔

 

Secure serving flags:

参数 

描述

--bind-address

监听安全端口的IP地址。必须能被集群的其他以及CLI/web客户机访问

--tls-cert-file

包含HTTPS的默认x509证书的文件。 CA证书,如果有的话,在服务器证书之后连接。如果启用了HTTPS服务,但未提供 --tls-cert-file和--tls-private-key-file,则会为公共地址生成自签名证书和密钥,并将其保存到--cert-dir指定的目录中。

 --tls-private-key-file包含和--tls-cert-file配对的默认x509私钥的文件

 

Insecure serving flags:

参数 

描述

--address ip监听的服务地址,(default 127.0.0.1)
--insecure-bind-address地址绑定到不安全服务端口,(default 127.0.0.1),将来会被remove
--insecure-port(default 8080)

 

Auditing flags:

参数 

描述

--audit-log-maxage根据文件名中的编码时间戳,保存审计日志文件的最大天数
audit-log-maxbackup保存审计日志文件的最大数量
audit-log-maxsize审计日志文件回滚前的最大大小(兆字节)
--audit-log-path

如果设置,所有到apiserver的请求都会记录到这个文件中。‘-’表示写入标准输出,不指定此参数会禁用日志后端

 

Features flags:

参数 

描述

--enable-swagger-ui启用swagger ui

 

Authentication flags:

参数 

描述

--anonymous-auth

允许匿名请求到API server的安全端口。未被其他身份验证方法拒绝的

请求将被视为匿名请求。匿名请求的system username:anonymous,

system group name:unauthenticated。默认值 true

--client-ca-file

启用客户端证书认证。该参数引用的文件中必须包含一个或多个证书颁发机构,用于验证提交给该组件的客户端证书。如果客户端证书已验证,则用其中的 Common Name 作为请求的用户名

--enable-bootstrap-token-auth

启用允许‘kube-system' namespace中的secrets类型的 'bootstrap.kubernetes.io/token'用于TLS引导身份验证

--requestheader-client-ca-file string 

根证书绑定包用于在信任--requestheader-username-headers指定的标头中的用户名前,在传入请求上验证客户证书

--service-account-key-file

包含PEM编码的x509 RSA或ECDSA私有或者公共密钥的文件。用于验证service account token。指定的文件可以包含多个值。参数可以被指定多个不同的文件。如未指定,--tls-private-key-file将被使用。如果提供了--service-account-signing-key,则必须指定该参数

--token-auth-file

使用该文件在安全端口通过token身份验证来保护API服务

--requestheader-allowed-names strings

List of client certificate common names to allow to provide usernames in headers specified by --requestheader-username-headers. If empty, any client certificate validated by the authorities in --requestheader-client-ca-file is allowed.

 

客户端证书常用名称列表,允许在--requestheader-username-headers指定的头中提供用户名,如果为空,则允许在--requestheader-client-ca文件中通过验证任何客户端证书

--requestheader-client-ca-file string

Root certificate bundle to use to verify client certificates on incoming requests before trusting usernames in headers specified by --requestheader-username-headers. WARNING: generally do not depend on authorization being already done for incoming requests.

 

根证书绑定包用于在信任--requestheader-username-headers 指定头中的用户名前,验证客户证书

--requestheader-extra-headers-prefix strings

List of request header prefixes to inspect. X-Remote-Extra- is suggested

 

要检查的请求头前缀列表。建议使用 X-Remote-Extra-

--requestheader-group-headers strings

List of request headers to inspect for groups. X-Remote-Group is suggested

 

要检查组的请求头列表。建议采用X-Remote组。

--requestheader-username-headers strings

List of request headers to inspect for usernames. X-Remote-User is common

 

要检查用户名的请求头列表。一般使用X-Remote-User

--proxy-client-cert-file string

Client certificate used to prove the identity of the aggregator or kube-apiserver when it must call out during a request. This includes proxying requests to a user api-server and calling out to webhook admission plugins. It is expected that this cert includes a signature from the CA in the --requestheader-client-ca-file flag. That CA is published in the 'extension-apiserver-authentication' configmap in the kube-system namespace. Components receiving calls from kube-aggregator should use that CA to perform their half of the mutual TLS verification.

 

用于证明 aggregator 或 kube-apiserver 在请求期间发出呼叫的身份的客户端证书,包括 api-server 的请求代理给以及对webhook准入插件的调用。此证书包括来自--requestheader-client-ca-file中的CA的签名。该CA在kube-system命名空间的 “extension-apiserver-authentication”  configmap中。被 kube-aggregator 调用的组件应该使用该CA来执行其TLS验证。

--proxy-client-key-file string

Private key for the client certificate used to prove the identity of the aggregator or kube-apiserver when it must call out during a request. This includes proxying requests to a user api-server and calling out to webhook admission plugins.

 

客户端证书的私钥,用于在请求期间证明 aggregator 或kube-apiserver的身份时。包括api-server的请求代理给以及对webhook准入插件的调用。

 

Authorization flags:

参数 

描述

--authorization-mode

在安全端口上执行授权的有序的插件列表。默认值:AlwaysAllow

以逗号分隔的列表:AlwaysAllow,AlwaysDeny,ABAC,Webhook,RBAC,Node.

  

 

Api enablement flags

参数

描述

--runtime-config mapStringString

一组键值对,描述可能传给apiserver的runtime配置。

 <group> / <version>(或核心组的<version>)键可用于打开/关闭特定的api版本。 api / all是控制所有api版本的特殊键,默认设置为false,除非你知道你做了什么。 api / legacy已弃用,将来会将其删除,请停止使用它。

--admission-control

准入控制过程分两个阶段。第一阶段,运行 mutating admission controllers。第二阶段,运行 validating admission controllers。有些控制器会运行两次。如果任一阶段中的任何控制器拒绝请求,则立即拒绝整个请求,并向最终用户返回错误。
AlwaysAdmit, AlwaysDeny, AlwaysPullImages, DefaultStorageClass, DefaultTolerationSeconds, DenyEscalatingExec, DenyExecOnPrivileged, EventRateLimit, ExtendedResourceToleration, ImagePolicyWebhook, Initializers, LimitPodHardAntiAffinityTopology, LimitRanger, MutatingAdmissionWebhook, NamespaceAutoProvision, NamespaceExists, NamespaceLifecycle, NodeRestriction, OwnerReferencesPermissionEnforcement, PersistentVolumeClaimResize, PersistentVolumeLabel, PodNodeSelector, PodPreset, PodSecurityPolicy, PodTolerationRestriction, Priority, ResourceQuota, SecurityContextDeny, ServiceAccount, StorageObjectInUseProtection, TaintNodesByCondition, ValidatingAdmissionWebhook

--advertise-address

向集群成员发布apiserver的IP地址,该地址必须能够被集群的成员访问。如果为空,则使用 --bind-address,如果 --bind-address未指定,那么使用主机的默认接口。

--bind-address

监听安全端口的IP地址。必须能被集群的其他以及CLI/web客户机访问

 

Misc flags:

参数 

描述

--allow-privilegedtrue允许特权模式的容器。默认值false
--apiserver-count集群中运行的 api server 数量,默认值 1

使用时--endpoint-reconciler-type=master-count时启用的

--event-ttl保留事件的时间。默认值 1h0m0s
--kubelet-https=truekubelet通信使用https,默认值 true
--service-account-signing-key-file

指向包含service account token签发方当前私钥文件的路径。签发方将用这个私钥签署已发行的ID token。

需要设置'TokenRequest' feature gate

--service-cluster-ip-rangeCIDR表示IP范围,用于分配服务集群IP。不能与分配给pod节点的IP重叠 (default 10.0.0.0/24)
--service-node-port-range portRange为NodePort服务保留的端口范围。默认值 30000-32767

 

Global flags:

参数 

描述

--alsologtostderr日志信息同时输出到stderr及文件
--logtostderr日志信息输出到stderr 而不是文件
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Kubernetes 中,API Server 是集群中的控制中心,所有的 Kubernetes API 调用都通过 API Server 进行。API Server 认证是 Kubernetes 中非常重要的一环,它确保了只有经过身份验证的用户才能够访问 Kubernetes API,并限制了用户能够访问的资源和操作。 Kubernetes 支持多种认证方式,例如 X.509 证书、Token、基于 HTTP Header 的认证等。下面我们以 X.509 证书认证为例,介绍如何启用 API Server 认证: 1. 生成证书和私钥 首先,需要使用 OpenSSL 工具生成证书和私钥。可以使用以下命令生成一个自签名的证书和私钥: ``` openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout tls.key -out tls.crt -subj "/CN=kube-apiserver" ``` 该命令生成一个有效期为 365 天的自签名证书和私钥,可以使用 -subj 参数指定证书的主题(这里指定为 kube-apiserver)。 2. 配置 API Server 启用 API Server 认证需要在 kube-apiserver启动参数中添加以下配置项: ``` --tls-cert-file=<path/to/tls.crt> --tls-private-key-file=<path/to/tls.key> --client-ca-file=<path/to/ca.crt> --authentication-mode=x509 ``` 其中,--tls-cert-file 和 --tls-private-key-file 分别指定 TLS 证书和私钥的路径,--client-ca-file 指定用于验证客户端证书的 CA 证书的路径,--authentication-mode 设置认证方式为 x509。 3. 配置 kubectl 为了使用证书进行认证,需要在 kubectl 的配置文件中添加以下配置项: ``` apiVersion: v1 kind: Config clusters: - name: my-cluster cluster: certificate-authority: /path/to/ca.crt users: - name: my-user user: client-certificate: /path/to/tls.crt client-key: /path/to/tls.key contexts: - name: my-context context: cluster: my-cluster user: my-user current-context: my-context ``` 其中,certificate-authority 指定用于验证服务器证书的 CA 证书的路径,client-certificate 和 client-key 分别指定客户端证书和私钥的路径。 4. 测试认证 完成上述步骤后,可以使用 kubectl 命令测试认证是否生效。例如,使用以下命令查看所有的 Pod: ``` kubectl get pods ``` 如果认证配置正确,则应该能够成功列出 Pod。如果认证失败,则会提示需要提供证书和私钥。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值