如何在 kubernetes 部署类型中覆盖 dnsconfig

mch*_*wre 5 dns docker kubernetes alpine-linux coredns

我正在尝试覆盖基于 alpine 的 pod 的 dnsconfig(特别是搜索域)。

但dnsconfig似乎在 pod 对象中可用。

无论如何,是否可以在部署对象中提供 dnsconfig 或任何其他解决方法来覆盖该特定 pod 的 searchdomain。

Cro*_*rou 4

您可以指定dnsConfig内部spec.template对象。

Deployment这基本上是一个用于创建 Pod的模板。

部署可能如下所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.17
        ports:
        - containerPort: 80
      dnsPolicy: "None"
      dnsConfig:
        nameservers:
          - 1.2.3.4
        searches:
          - test.test.com
          - test.test.org
Run Code Online (Sandbox Code Playgroud)