- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
遇到了以下问题:
我需要在一些 pod 上添加一个搜索域,以便能够与 headless 服务进行通信。 Kubernetes 文档建议设置一个 dnsConfig 并在其中设置所有内容。这就是我所做的。还有一个限制是只能设置 6 个搜索域。
部分 list :
spec:
hostname: search
dnsPolicy: ClusterFirst
dnsConfig:
searches:
- indexer.splunk.svc.cluster.local
containers:
- name: search
search splunk.svc.cluster.local svc.cluster.local cluster.local us-east4-c.c.'project-id'.internal c.'project-id'.internal google.internal
nameserver 10.39.240.10
options ndots:5
---
# Search-head deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: search
namespace: splunk
labels:
app: splunk
spec:
replicas: 1
selector:
matchLabels:
app: splunk
template:
metadata:
labels:
app: splunk
spec:
hostname: search
dnsPolicy: ClusterFirst
dnsConfig:
searches:
- indexer.splunk.svc.cluster.local
containers:
- name: search
image: splunk/splunk
env:
- name: SPLUNK_START_ARGS
value: "--accept-license"
- name: SPLUNK_PASSWORD
valueFrom:
secretKeyRef:
name: splunk-password
key: password
- name: SPLUNK_ROLE
value: splunk_search_head
- name: SPLUNK_SEARCH_HEAD_URL
value: search
- name: SPLUNK_INDEXER_URL # TODO: make this part dynamic.
value: indexer-0,indexer-1
ports:
- name: web
containerPort: 8000
- name: mgmt
containerPort: 8089
- name: kv
containerPort: 8191
volumeMounts:
- mountPath: /opt/splunk/var
name: sh-volume
volumes:
- name: sh-volume
persistentVolumeClaim:
claimName: sh-volume
最佳答案
根据 Pods DnsConfig Documentation :
searches
: a list of DNS search domains for hostname lookup in the Pod. This property is optional. When specified, the provided list will be merged into the base search domain names generated from the chosen DNS policy. Duplicate domain names are removed. Kubernetes allows for at most 6 search domains.
InitContainer
创建一个新的 resolv.conf
并挂载到 pod容器启动后,它会替换自动生成的容器。resolv.conf
总会得到加强。 apiVersion: apps/v1
kind: Deployment
metadata:
name: search
namespace: default
labels:
app: splunk
spec:
replicas: 1
selector:
matchLabels:
app: splunk
template:
metadata:
labels:
app: splunk
spec:
hostname: search
initContainers:
- name: initdns
image: nginx
imagePullPolicy: IfNotPresent
command: ["/bin/bash","-c"]
args: ["echo -e \"nameserver 10.39.240.10\nsearch indexer.splunk.svc.cluster.local splunk.svc.cluster.local svc.cluster.local cluster.local us-east4-c.c.'project-id'.internal c.'project-id'.internal google.internal\noptions ndots:5\n \" > /mnt/resolv.conf"]
volumeMounts:
- mountPath: /mnt
name: volmnt
containers:
- name: search
image: nginx
env:
- name: SPLUNK_START_ARGS
value: "--accept-license"
- name: SPLUNK_PASSWORD
value: password
- name: SPLUNK_ROLE
value: splunk_search_head
- name: SPLUNK_SEARCH_HEAD_URL
value: search
ports:
- name: web
containerPort: 8000
- name: mgmt
containerPort: 8089
- name: kv
containerPort: 8191
volumeMounts:
- mountPath: /mnt
name: volmnt
command: ["/bin/bash","-c"]
args: ["cp /mnt/resolv.conf /etc/resolv.conf ; nginx -g \"daemon off;\""]
volumes:
- name: volmnt
emptyDir: {}
namespace
, nameserver
, container.image
, container.args
$ kubectl apply -f search-head-splunk.yaml
deployment.apps/search created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
search-64b6fb5854-shm2x 1/1 Running 0 5m14sa
$ kubectl exec -it search-64b6fb5854-shm2x -- cat /etc/resolv.conf
nameserver 10.39.240.10
search indexer.splunk.svc.cluster.local splunk.svc.cluster.local svc.cluster.local cluster.local us-east4-c.c.'project-id'.internal c.'project-id'.internal google.internal
options ndots:5
kube-dns
服务在集群生命周期内坚持使用相同的 IP,有时甚至在集群重新创建之后,这取决于网络配置。 dnsPolicy
至 None
并跳过 InitContainer
:apiVersion: apps/v1
kind: Deployment
metadata:
name: search
namespace: splunk
labels:
app: splunk
spec:
replicas: 1
selector:
matchLabels:
app: splunk
template:
metadata:
labels:
app: splunk
spec:
hostname: search
dnsPolicy: "None"
dnsConfig:
nameservers:
- 10.39.240.10
searches:
- indexer.splunk.svc.cluster.local
- splunk.svc.cluster.local
- us-east4-c.c.'project-id'.internal
- c.'project-id'.internal
- svc.cluster.local
- cluster.local
options:
- name: ndots
- value: "5"
containers:
- name: search
image: splunk/splunk
...
{{{the rest of your config}}}
关于kubernetes - dnsConfig 在 GKE 中被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60508061/
遇到了以下问题: 我需要在一些 pod 上添加一个搜索域,以便能够与 headless 服务进行通信。 Kubernetes 文档建议设置一个 dnsConfig 并在其中设置所有内容。这就是我所做的
因为我面临着 issue,所以我覆盖了 pod 的 dns 策略默认 /etc/resolv.conf pod 的。另一个问题是由于默认 /etc/resolv.conf,pod 无法连接到 smtp
我的目标: 使用 Karma/Jasmine 在我的 Angular 6 应用程序(在 Docker 容器内运行)上运行单元测试。为了运行这些测试,我似乎需要一个网络浏览器。所以看起来 Chromiu
我是一名优秀的程序员,十分优秀!