k8s-自定义DNS和hosts

摘要:k8s-自定义DNS和hosts

istio-deployment.yml文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
apiVersion: apps/v1
kind: Deployment
metadata:
name: cas
namespace: cloud
labels:
app: cas
spec:
replicas: 1
selector:
matchLabels:
app: cas
template:
metadata:
labels:
app: cas
annotations:
traffic.sidecar.istio.io/excludeOutboundIPRanges: 0.0.0.0/0
spec:
containers:
- image: harbor.demo.com/cloud/cas:4.1.18
name: cas
imagePullPolicy: IfNotPresent # 镜像拉取策略
dnsConfig:
nameservers:
- 10.10.10.10
hostAliases:
- ip: "10.20.30.40"
hostnames:
- "test123.demo.com"

其中dnsConfig的效果,是往容器的 /etc/resolv.conf 文件中添加记录:

1
2
3
4
5
6
/ # cat /etc/resolv.conf 
nameserver 10.68.0.2
nameserver 10.10.10.10
search cloud.svc.cluster.local. svc.cluster.local. cluster.local.
options ndots:5
/ #

其中hostAliases的效果,是往容器的 /etc/hosts 文件中添加记录:

1
2
3
4
5
6
7
8
9
10
11
12
/ # cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
172.20.1.19 cas-7f8687755b-brqfm

# Entries added by HostAliases.
10.20.30.40 test123.demo.com