Kubernetes DNS服务配置案例
首先创建DNS服务的RC配置文件skydns-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: kube-dns-v8
namespace: kube-system
labels:
k8s-app: kube-dns
version: v8
kubernetes.io/cluster-service: "true"
spec:
replicas: 1
selector:
k8s-app: kube-dns
version: v8
template:
metadata:
labels:
k8s-app: kube-dns
version: v8
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: etcd
image: googlecontainer/etcd:2.0.9
resources:
limits:
cpu: 100m
memory: 50Mi
command:
- /usr/local/bin/etcd
- -data-dir
- /var/etcd/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: /var/etcd/data
- name: kube2sky
image: googlecontainer/kube2sky:1.11
resources:
limits:
cpu: 100m
memory: 50Mi
args:
# command = "/kube2sky"
- --kube_master_url=http://39.108.97.109:8080 #根据实际修改
- -domain=cluster.local
- name: skydns
image: googlecontainer/skydns:2015-03-11-001
resources:
limits:
cpu: 100m
memory: 50Mi
args:
# command = "/skydns"
- -machines=http://localhost:4001
- -addr=0.0.0.0:53
- -domain=cluster.local
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: 8080
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
volumes:
- name: etcd-storage
emptyDir: {}
dnsPolicy: Default # Don't use cluster DNS.
创建DNS服务的Service配置文件skydns-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: kube-dns
namespace: kube-system
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "KubeDNS"
spec:
selector:
k8s-app: kube-dns
clusterIP: 10.254.0.100 #根据实际修改
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
protocol: TCP
创建RC和Service,然后修改每台Node上Kubelet的启动参数,配置文件/etc/kubernetes/kubelet,修改后重启Kubelet。--resolv-conf=''不继承宿主机/etc/resolv.conf配置。
--cluster_dns=10.254.0.100
--cluster_domain=cluster.local
--resolv-conf=''
创建Pod busybox.yaml 用于测试DNS解释是否成功
apiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
containers:
- image: googlecontainer/busybox
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
name: busybox
restartPolicy: Always
测试命令和结果
# kubectl exec busybox -- nslookup mysql Server: 10.254.0.100 Address 1: 10.254.0.100 Name: mysql Address 1: 10.254.67.179
参考资料
https://github.com/kubernetes/kubernetes/blob/v1.0.1/cluster/addons/dns/skydns-rc.yaml.in