K8S 设置 Pod 使用 host 网络、配置 DNS
如果希望 Pod 可以使用宿主机的网络,可以添加 hostNetwork: true
apiVersion: apps/v1
kind: Deployment
metadata:
name: spark-app
labels:
app: spark-app
spec:
selector:
matchLabels:
app: spark-app
replicas: 1
template:
metadata:
labels:
app: spark-app
spec:
hostNetwork: true
containers:
- name: spark-app
image: spark-app-image
但这样起来后似乎就用不了 K8S 配置的 Service 的域名
K8S 使用的 DNS 是 Core DNS,可以在这里添加新的域名、IP
lin@lin-virtual-box:~$ kubectl get cm -n kube-system
NAME DATA AGE
coredns 2 33d
extension-apiserver-authentication 6 33d
kube-proxy 2 33d
kubeadm-config 2 33d
kubelet-config-1.16 1 33d
kubectl edit cm coredns -n kube-system
apiVersion: v1
data:
Corefile: |
.:53 {
errors
health
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
hosts {
202.35.32.100 host-name
fallthrough
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
reload
loadbalance
}