k8s修改pod的hosts文件

时间:2021-04-14 13:59:08

1、在1.7版本后使用HostAliases修改pod的hosts文件。该文件由kubelet管理

在deployment的yaml文件中添加在pod template 的spec里面即可:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: runner
name: gitlab-runner-gitlab-runner
spec:
replicas:
selector:
matchLabels:
app: runner
strategy:
rollingUpdate:
maxSurge:
maxUnavailable:
type: RollingUpdate
template:
metadata:
labels:
app: runner
spec:
dnsPolicy: None
dnsConfig:
nameservers:
- 10.3.9.13
- 10.3.9.11
searches:
- gitlab.klog.com
- reg.klog.com
options:
- name: ndots
value: ""
- name: edns0
hostAliases:
- hostnames:
- gitlab.klog.com
ip: 10.3.2.13
- hostnames:
- reg.klog.com
ip: 10.3.2.11
imagePullSecrets:
- name: registry-secrete

nameservers:是自己的内网dns

禁止访问外网,走hostaliases。