22. 如何自定义 rke2-coredns
上述示例中使用了完整的 Corefile 内容来设置主机插件的值。这是必要的,因为 helm 值中不能附加到列表中,结合其他 coredns 的 helm 值变更时需谨慎。该文件必须在 RKE2 集群内的每个服务器节点创建,rke2-server 服务会检测该目录中文件的变化并将其应用到集群上。这可以用来自定义 RKE2 封装的组合,如 Canal、CoreDNS 和 ingress-nginx。
牧场配置或独立 RKE2 集群
RKE2 允许使用 HelmChartConfig 资源来定制部署为 Helm Charts 的附加包。这可以用来自定义 RKE2 封装的组合,如 Canal、CoreDNS 和 ingress-nginx。
Details on the customization of components via HelmChartConfig resources can be found within the RKE2 documentation.
关于通过 HelmChartConfig 资源定制组件的详细信息,可以在 RKE2 文档中找到。
In the example below, we will use a HelmChartConfig to add a custom zonefile to rke2-coredns for the domain example.com:
在下面的示例中,我们将使用 HelmChartConfig 为 rke2-coredns 域 example.com 添加自定义区域文件:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#f3f3f3">apiVersion: <a data-cke-saved-href="http://helm.cattle.io/v1" href="http://helm.cattle.io/v1">helm.cattle.io/v1</a>
kind: HelmChartConfig
metadata:
name: rke2-coredns
namespace: kube-system
spec:
valuesContent: |-
zoneFiles:
- filename: example.com.conf
domain: <a data-cke-saved-href="http://example.com/" href="http://example.com/">example.com</a>
contents: |
<a data-cke-saved-href="http://example.com/" href="http://example.com/">example.com</a>:53 {
errors
cache 30
forward . 10.0.254.1
}
extraConfig:
import:
parameters: /etc/coredns/example.com.conf</span></span></span>
In the next sample, we'll use a HelmChartConfig to modify the default root '.' zonefile for rke2-coredns, adding some host entries using the hosts plugin:
在下一个示例中,我们将使用 HelmChartConfig 修改默认根 '.' 用于 RKE2-coreDNS 的 zonefile,通过 hosts 插件添加一些 host 条目:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>apiVersion: <a data-cke-saved-href="http://helm.cattle.io/v1" href="http://helm.cattle.io/v1">helm.cattle.io/v1</a>
kind: HelmChartConfig
metadata:
name: rke2-coredns
namespace: kube-system
spec:
valuesContent: |-
zoneFiles:
- filename: Corefile
contents: |
.:53 {
errors
health {
lameduck 10s
}
ready
kubernetes cluster.local cluster.local <a data-cke-saved-href="http://in-addr.arpa/" href="http://in-addr.arpa/">in-addr.arpa</a> <a data-cke-saved-href="http://ip6.arpa/" href="http://ip6.arpa/">ip6.arpa</a> {
pods insecure
fallthrough <a data-cke-saved-href="http://in-addr.arpa/" href="http://in-addr.arpa/">in-addr.arpa</a> <a data-cke-saved-href="http://ip6.arpa/" href="http://ip6.arpa/">ip6.arpa</a>
ttl 30
}
prometheus 0.0.0.0:9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
hosts {
10.1.1.1 web1.local
10.1.1.2 web2.local
10.90.3.1 <a data-cke-saved-href="http://sql.prod.space.net/" href="http://sql.prod.space.net/">sql.prod.space.net</a>
fallthrough
}</code></span></span></span>
Note: the full Corefile content is used in the above example to set the hosts plugin values. This is needed as items can't be appended to a list in helm values, care should be taken when combining this with other helm value changes for coredns.
注意: 上述示例中使用了完整的 Corefile 内容来设置主机插件的值。这是必要的,因为 helm 值中不能附加到列表中,结合其他 coredns 的 helm 值变更时需谨慎。
Rancher-provisioned RKE2 cluster
牧场配置 RKE2 集群
To apply this HelmChartConfig customization in a Rancher-provisioned RKE2 cluster, navigate to the Cluster Management view and click Edit Config for the desired cluster. Click the Add-On Config tab and add the HelmChartConfig manifest into the Additional Manifest section, before clicking Save.
要在 Rancher 配置的 RKE2 集群中应用此 HelmChartConfig 自定义,请进入集群管理 视图,点击 所需集群的编辑配置 。点击 “附加配置 ”标签,将 HelmChartConfig 清单 添加到 “附加清单 ”部分,然后点击 保存 。
Standalone RKE2 cluster 独立 RKE2 集群
Create the file /var/lib/rancher/rke2/server/manifests/rke2-coredns-config.yaml, containing the HelmChartConfig manifest content. The file must be created on every server node within the RKE2 cluster, the rke2-server service will detect changes to the files in this directory and apply these to the cluster.
创建包含 HelmChartConfig 清单内容的文件 /var/lib/rancher/rke2/server/manifests/rke2-coredns-config.yaml 。该文件必须在 RKE2 集群内的每个服务器节点创建,rke2-server 服务会检测该目录中文件的变化并将其应用到集群上。
Verify the customization 验证定制
In this case, with a customization to the rke2-coredns configuration, the configmap rke2-coredns-rke2-coredns can be reviewed to determine if the change was successful:
在这种情况下,通过对 rke2-coredns 配置进行自定义,可以审查 configmap rke2-coredns-rke2-coredns 以判断更改是否成功:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#f3f3f3">kubectl -n kube-system get configmap rke2-coredns-rke2-coredns -o json</span></span></span>
更多推荐
所有评论(0)