Kubernetes提供的虚拟DNS服务名为skydns,由四个组件组成:
- etcd:DNS存储
- kube2sky:将Kubernetes Master中的Service(服务)注册到etcd
- skyDNS:提供DNS域名解析服务
- healthz:提供对skydns服务的健康检查功能。
Kubernetes DNS服务的总体架构:
skydns-rc.yaml文件中需要修改几个参数:
- kube2sky容器需要访问Kubernetes Master,需要配置Master所在物理主机的IP地址和端口号,--kube-master-url的值为http://192.168.1.191:8080。
- kube2sky容器和skydns容器的启动参数--domain,设置Kubernetes集群中Service所属的域名,本例中为cluster.local,启动后,kube2sky会通过APIserver监控集群中全部Service的定义,生成相应的记录保存在etcd中。kube2sky为每个Service生成以下两条记录:
- <service_name>.<namespace_name>.<domain>
- <service_name>.<namespace_name>.svc.<domain>
- skydns的启动参数--addr=0.0.0.0:35 表示使用本机TCP和UDP的53端口提供服务。
- cat skydns-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: kube-dns-v11
namespace: kube-system
labels:
k8s-app: kube-dns
version: v11
kubernetes.io/cluster-service: "true"
spec:
replicas: 1
selector:
k8s-app: kube-dns
version: v11
template:
metadata:
labels:
k8s-app: kube-dns
version: v11
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: etcd
image: 192.168.1.191:5000/etcd:latest
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
command:
- etcd
- -data-dir
- /tmp/data
- -listen-client-urls
- http://127.0.0.1:2379,http://127.0.0.1:4001
- -advertise-client-urls
- http://127.0.0.1:2379,http://127.0.0.1:4001
- -initial-cluster-token
- skydns-etcd
volumeMounts:
- name: etcd-storage
mountPath: /tmp/data
- name: kube2sky
image: 192.168.1.191:5000/kube2sky:kubernetes
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
livenessProbe:
httpGet:
path: /healthz
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /readiness
port: 8081
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
args:
- --kube-master-url=http://192.168.1.191:8080
- --domain=cluster.local
- name: skydns
image: 192.168.1.191:5000/skydns:latest
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
command:
- /skydns
- -machines=http://127.0.0.1:4001
- -addr=0.0.0.0:53
- -ns-rotate=false
- -domain=cluster.local
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- name: healthz
image: 192.168.1.191:5000/exechealthz-amd64:latest
resources:
limits:
cpu: 10m
memory: 20Mi
requests:
cpu: 10m
memory: 20Mi
args:
- -cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 > /dev/null
- -port= 8080
ports:
- containerPort: 8080
protocol: TCP
volumes:
- name: etcd-storage
emptyDir: {}
dnsPolicy: Default