> 文章列表 > deployment 单独对pod中设置dns

deployment 单独对pod中设置dns

deployment 单独对pod中设置dns

1.因为一个项目需要用到内网dns,而其他项目只能用阿里云的nds,所以就需要单独对pod设置dns,这个是智搜项目

Pod的DNS策略

    DNS 策略可以逐个 Pod 来设定。目前 Kubernetes 支持以下特定 Pod 的 DNS 策略。 这些策略可以在 Pod 规约中的 dnsPolicy 字段设置。

Default:

    Pod 从运行所在的节点继承名称解析配置。

ClusterFirst:

    与配置的集群域后缀不匹配的任何 DNS 查询(例如 "www.kubernetes.io") 都将转发到从节点继承的上游名称服务器。集群管理员可能配置了额外的存根域和上游 DNS 服务器。

ClusterFirstWithHostNet:

    对于以 hostNetwork 方式运行的 Pod,应显式设置其 DNS 策略 ClusterFirstWithHostNet。

None:

    此设置允许 Pod 忽略 Kubernetes 环境中的 DNS 设置。Pod 会使用其 dnsConfig 字段 所提供的 DNS 设置。

示例:

apiVersion: v1
kind: Pod
metadata:
name: alpine
namespace: default
spec:
containers:

  • image: alpine
    command:
    • sleep
    • “10000”
      imagePullPolicy: Always
      name: alpine
      dnsPolicy: None # 忽略k8s的dns设置,使用自定义设置
      dnsConfig:
      nameservers:
    • 114.114.114.114 # DNS地址,不能光设置个地址,后面的search也要带上
    • 223.5.5.5
      searches:
    • default.svc.cluster.local
    • svc.cluster.local
    • cluster.local
      options:
    • name: ndots # 域名中包含点的个数比配置的ndots小就会追加search中的后缀来查找
      value: “5”
      2.实际应用
apiVersion: apps/v1
kind: Deployment  
metadata:  name: @APP_NAME@labels:  app: @APP_NAME@
spec:  replicas: @REPLICAS@revisionHistoryLimit: 10selector:  matchLabels:  app: @APP_NAME@template:  metadata:  labels:  app: @APP_NAME@armsPilotAutoEnable: "on"armsPilotCreateAppName: @APP_NAME@one-agent.jdk.version: "OpenJDK11"spec:dnsPolicy: NonednsConfig:nameservers:- 10.33.2.5searches:- default.svc.cluster.local- svc.cluster.local- cluster.localoptions:- name: ndotsvalue: "5"  imagePullSecrets:  - name: osale-secret  containers:  - name: @APP_NAME@image: ${IMAGE}ports:  - containerPort: @targetPort@protocol: TCP  imagePullPolicy: IfNotPresentreadinessProbe:tcpSocket:port: 8080initialDelaySeconds: 30periodSeconds: 10livenessProbe:tcpSocket:port: 8080initialDelaySeconds: 15periodSeconds: 20resources:limits:cpu: @LIMIT_CPU@memory: @LIMIT_MEMORY@requests:cpu: @REQUEST_CPU@memory: @REQUEST_MEMORY@volumeMounts:- name: logsmountPath: /gemdale/logs- name: datamountPath: /gemdata/share/volumes:- name: logshostPath:type: DirectoryOrCreate path: /data/logs/pre/@APP_NAME@ - name: datahostPath:type: DirectoryOrCreate path: /gemdata/share/---  
apiVersion: v1  
kind: Service  
metadata:  name: @APP_NAME@labels:  app: @APP_NAME@
spec:  ports:  - port: @port@targetPort: @targetPort@@NodePort@selector:  app: @APP_NAME@type: @PORT_TYPE@