±¾ÎĽ«ÔÚÇ°ÎĵĻù´¡ÉϽéÉÜÔÚkubernetes¼¯Èº»·¾³ÖÐÅäÖÃdns·þÎñ£¬ÔÚk8s¼¯ÈºÖУ¬podµÄÉúÃüÖÜÆÚÊǶÌÔݵģ¬podÖØÆôºóipµØÖ·»á²úÉú±ä»¯£¬¶ÔÓÚÓ¦ÓóÌÐòÀ´ËµÕâÊDz»¿É½ÓÊܵģ¬Îª½â¾öÕâ¸öÎÊÌ⣬K8S¼¯ÈºÇÉÃîµÄÒýÈëµÄdns·þÎñÀ´ÊµÏÖ·þÎñµÄ·¢ÏÖ£¬ÔÚk8s¼¯ÈºÖÐdns×ܹ²ÐèҪʹÓÃ4¸ö×é¼þ£¬¸÷×é¼þ·Ö¹¤ÈçÏ£º
etcd£ºDNS´æ´¢
kube2sky£º½«Kubernetes MasterÖеÄservice£¨·þÎñ£©×¢²áµ½etcd¡£
skyDNS£ºÌṩDNSÓòÃû½âÎö·þÎñ¡£
healthz£ºÌṩ¶Ôskydns·þÎñµÄ½¡¿µ¼ì²é¡£
Ò»¡¢ÏÂÔØÏà¹Ø¾µÏñÎļþ£¬²¢ÄÉÈë±¾µØ²Ö¿âͳһ¹ÜÀí
# docker pull docker.io/elcolio/etcd
# docker pull docker.io/port/kubernetes-kube2sky
# docker pull docker.io/skynetservices/skydns
# docker pull docker.io/wu1boy/healthz
# docker tag docker.io/elcolio/etcd registry.fjhb.cn/etcd
# docker tag docker.io/port/kubernetes-kube2sky registry.fjhb.cn/kubernetes-kube2sky
# docker tag docker.io/skynetservices/skydns registry.fjhb.cn/skydns
# docker tag docker.io/wu1boy/healthz registry.fjhb.cn/healthz
# docker push registry.fjhb.cn/etcd
# docker push registry.fjhb.cn/kubernetes-kube2sky
# docker push registry.fjhb.cn/skydns
# docker push registry.fjhb.cn/healthz
# docker images |grep fjhb
¶þ¡¢Í¨¹ýrcÎļþ´´½¨pod
ÕâÀïÃæÒ»¸öpod°üº¬ÁË4¸ö×é¼þ£¬Ò»¸ö×é¼þÔËÐÐÔÚÒ»¸ödockerÈÝÆ÷ÖÐ
# cat skydns-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: kube-dns
namespace: default
labels:
k8s-app: kube-dns
version: v12
kubernetes.io/cluster-service: "true"
spec:
replicas: 1
selector:
k8s-app: kube-dns
version: v12
template:
metadata:
labels:
k8s-app: kube-dns
version: v12
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: etcd
image: registry.fjhb.cn/etcd
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
command:
- /bin/etcd
- --data-dir
- /tmp/data
- --listen-client-urls
- http:
- --advertise-client-urls
- http:
- --initial-cluster-token
- skydns-etcd
volumeMounts:
- name: etcd-storage
mountPath: /tmp/data
- name: kube2sky
image: registry.fjhb.cn/kubernetes-kube2sky
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
args:
- -kube_master_url=http:
- -domain=cluster.local
- name: skydns
image: registry.fjhb.cn/skydns
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
args:
- -machines=http:
- -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: registry.fjhb.cn/healthz
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
Èý¡¢Í¨¹ýsrvÎļþ´´½¨service
apiVersion: v1
kind: Service
metadata:
name: kube-dns
namespace: default
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "KubeDNS"
spec:
selector:
k8s-app: kube-dns
clusterIP: 10.254.16.254
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
protocol: TCP
# kubectl create -f skydns-rc.yaml
# kubectl create -f skydns-svc.yaml
# kubectl get rc
# kubectl get pod
# kubectl get svc
# kubectl describe svc kube-dns
# kubectl describe rc kube-dns
# kubectl describe pod kube-dns-9fllp
Name: kube-dns-9fllp
Namespace: default
Node: 192.168.115.6/192.168.115.6
Start Time: Tue, 23 Jan 2018 10:55:19 -0500
Labels: k8s-app=kube-dns
kubernetes.io/cluster-service=true
version=v12
Status: Running
IP: 172.16.37.5
Controllers: ReplicationController/kube-dns
Containers:
etcd:
Container ID: docker:
Image: registry.fjhb.cn/etcd
Image ID: docker-pullable:
Port:
Command:
/bin/etcd
--data-dir
/tmp/data
--listen-client-urls
http:
--advertise-client-urls
http:
--initial-cluster-token
skydns-etcd
Limits:
cpu: 100m
memory: 50Mi
Requests:
cpu: 100m
memory: 50Mi
State: Running
Started: Tue, 23 Jan 2018 10:55:23 -0500
Ready: True
Restart Count: 0
Volume Mounts:
/tmp/data from etcd-storage (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6pddn (ro)
Environment Variables: <none>
kube2sky:
Container ID: docker:
Image: registry.fjhb.cn/kubernetes-kube2sky
Image ID: docker-pullable:
Port:
Args:
-kube_master_url=http:
-domain=cluster.local
Limits:
cpu: 100m
memory: 50Mi
Requests:
cpu: 100m
memory: 50Mi
State: Running
Started: Tue, 23 Jan 2018 10:55:25 -0500
Ready: True
Restart Count: 0
Volume Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6pddn (ro)
Environment Variables: <none>
skydns:
Container ID: docker:
Image: registry.fjhb.cn/skydns
Image ID: docker-pullable:
Ports: 53/UDP, 53/TCP
Args:
-machines=http:
-addr=0.0.0.0:53
-ns-rotate=false
-domain=cluster.local
Limits:
cpu: 100m
memory: 50Mi
Requests:
cpu: 100m
memory: 50Mi
State: Running
Started: Tue, 23 Jan 2018 10:55:27 -0500
Ready: True
Restart Count: 0
Volume Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6pddn (ro)
Environment Variables: <none>
healthz:
Container ID: docker:
Image: registry.fjhb.cn/healthz
Image ID: docker-pullable:
Port: 8080/TCP
Args:
-cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 >/dev/null
-port=8080
Limits:
cpu: 10m
memory: 20Mi
Requests:
cpu: 10m
memory: 20Mi
State: Running
Started: Tue, 23 Jan 2018 10:55:29 -0500
Ready: True
Restart Count: 0
Volume Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6pddn (ro)
Environment Variables: <none>
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
etcd-storage:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
default-token-6pddn:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-6pddn
QoS Class: Guaranteed
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
7m 7m 1 {default-scheduler } Normal Scheduled Successfully assigned kube-dns-9fllp to 192.168.115.6
7m 7m 1 {kubelet 192.168.115.6} spec.containers{etcd} Normal Pulling pulling image "registry.fjhb.cn/etcd"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{etcd} Normal Pulled Successfully pulled image "registry.fjhb.cn/etcd"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{etcd} Normal Created Created container with docker id 62ad76bfaca1; Security:[seccomp=unconfined]
7m 7m 1 {kubelet 192.168.115.6} spec.containers{kube2sky} Normal Pulled Successfully pulled image "registry.fjhb.cn/kubernetes-kube2sky"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{etcd} Normal Started Started container with docker id 62ad76bfaca1
7m 7m 1 {kubelet 192.168.115.6} spec.containers{kube2sky} Normal Pulling pulling image "registry.fjhb.cn/kubernetes-kube2sky"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{kube2sky} Normal Created Created container with docker id 6b0bc6e8dce8; Security:[seccomp=unconfined]
7m 7m 1 {kubelet 192.168.115.6} spec.containers{skydns} Normal Pulled Successfully pulled image "registry.fjhb.cn/skydns"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{skydns} Normal Pulling pulling image "registry.fjhb.cn/skydns"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{kube2sky} Normal Started Started container with docker id 6b0bc6e8dce8
7m 7m 1 {kubelet 192.168.115.6} spec.containers{skydns} Normal Created Created container with docker id ebc2aaaa54e2; Security:[seccomp=unconfined]
7m 7m 1 {kubelet 192.168.115.6} spec.containers{skydns} Normal Started Started container with docker id ebc2aaaa54e2
7m 7m 1 {kubelet 192.168.115.6} spec.containers{healthz} Normal Pulling pulling image "registry.fjhb.cn/healthz"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{healthz} Normal Pulled Successfully pulled image "registry.fjhb.cn/healthz"
7m 7m 1 {kubelet 192.168.115.6} spec.containers{healthz} Normal Created Created container with docker id f1de1189fa6b; Security:[seccomp=unconfined]
7m 7m 1 {kubelet 192.168.115.6} spec.containers{healthz} Normal Started Started container with docker id f1de1189fa6b
ËÄ¡¢ÐÞ¸ÄkubeletÅäÖÃÎļþ²¢ÖØÆô·þÎñ
×¢Òâ:
--cluster-dns²ÎÊýÒªºÍÇ°ÃæsvcÎļþÖеÄclusterIP²ÎÊýÒ»ÖÂ
--cluster-domain²ÎÊýÒªºÍÇ°ÃærcÎļþÖеÄ-domain²ÎÊýÒ»ÖÂ
¼¯ÈºÄÚËùÓеÄkubelet½Úµã¶¼ÐèÒªÐÞ¸Ä
KUBELET_ADDRESS="--address=192.168.115.5 --cluster-dns=10.254.16.254 --cluster-domain=cluster.local"
Îå¡¢ÔËÐÐÒ»¸öbusyboxºÍcurl½øÐвâÊÔ
apiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
containers:
- name: busybox
image: docker.io/busybox
command:
- sleep
- "3600"
apiVersion: v1
kind: Pod
metadata:
name: curl
spec:
containers:
- name: curl
image: docker.io/webwurst/curl-utils
command:
- sleep
- "3600"
# kubectl create -f busybox.yaml
# kubectl create -f curl.yaml
ͨ¹ýbusyboxÈÝÆ÷¶ÔkubernetesµÄservice½øÐнâÎö£¬·¢ÏÖservice±»×Ô¶¯½âÎö³ÉÁ˶ÔÓ¦µÄ¼¯ÈºipµØÖ·£¬¶ø²¢²»ÊÇ172.16Íø¶ÎµÄdockerµØÖ·
# kubectl get svc
# kubectl exec busybox -- nslookup frontend
# kubectl exec busybox -- nslookup redis-master
# kubectl exec busybox -- nslookup redis-slave
ͨ¹ýcurlÈÝÆ÷·ÃÎÊÇ°Ãæ´´½¨µÄphpÁôÑÔ°å
# kubectl exec curl -- curl frontend
(ÔðÈα༣ºIT) |