Kubernetes Cluster Configuration DNS Service

Source: Internet
Author: User
Tags curl nslookup etcd k8s


Kubernetes cpu limit
This article will be based on the previous article on the configuration of the DNS service in the Kubernetes cluster environment, in the k8s cluster, pod life cycle is short, pod restart IP address will change, for the application this is unacceptable, in order to solve this problem, The k8s cluster cleverly introduces the DNS service to realize the discovery of the service, in which DNS requires a total of 4 components in the k8s cluster, each of which is divided into the following components:
Etcd:dns Storage
Kube2sky: Register Service (Service) in Kubernetes Master to Etcd.
Skydns: Provides DNS domain name resolution service.
Healthz: Provides a health check on the Skydns service.

Cpu limit kubernetes 

First, kubernetes cpu memory limits download the relevant image files,kubernetes cpu limits vs requests  and integrate into the local warehouse unified management



# 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


Kubernetes cpu limit 0

Second, create pod through RC file
There's a pod in it that contains 4 components, one component running in a Docker container

Cpu requests and limits kubernetes

# cat Skydns-rc.yamlapiversion:v1kind:replicationcontrollermetadata: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/clu          Ster-service: "True" spec:containers:-NAME:ETCD IMAGE:REGISTRY.FJHB.CN/ETCD Resources: limits:cpu:100m memory:50mi requests:cpu:100m memory:50m I command:-/bin/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:registry.fjhb.cn/kubernetes-kube2sky resources:limits:cpu:100m Memory:50mi requests:cpu:100m memory:50mi args:--kube_master_url=         http://192.168.115.5:8080--domain=cluster.local-name:skydns Image:registry.fjhb.cn/skydns            resources:limits:cpu:100m memory:50mi requests:cpu:100m        Memory:50mi args:--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:registry.fjhb.cn/healt            Hz 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


Iii. creating a service from an SRV file



# cat skydns-svc.yaml   apiVersion: v1kind: Servicemetadata:  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-9fllpname:kube-dns-9fllpnamespace:defaultnode:192.168.115.6/19 2.168.115.6Start time:tue, 2018 10:55:19-0500labels:k8s-app=kube-dns KUBERNETES.IO/CL Uster-service=true version=v12status:runningip:172.16.37.5controllers:replication Controller/kube-dnscontainers:etcd:container ID:DOCKER://62AD76BFACA1797C5F43B0E9EEBC04074169FCE4CC15EF3FFC4C D19ffa9c8c19 IMAGE:REGISTRY.FJHB.CN/ETCD Image Id:docker-pullable://docker.io/elcolio/[emai      l protected]:3b4dcd35a7eefea9ce2970c81dcdf0d0801a778d117735ee1d883222de8bbd9f Port:command:/bin/etcd --data-dir/tmp/data--listen-client-urls http://127.0.0.1:2379,http://127.0.0.1:4001--ADVERTISE-CL Ient-urls http://127.0.0.1:2379,http://127.0.0.1:4001--initial-cluster-token Skydns-etcd limits:c pu:100m MemorY:50mi requests:cpu:100m memory:50mi state:running Started : Tue, Jan 2018 10:55:23-0500 ready:true Restart count:0 Volume Mounts:/tm P/data from Etcd-storage (rw)/var/run/secrets/kubernetes.io/serviceaccount from Default-token-6pddn (RO) Environm ENT Variables: <none> kube2sky:container id:docker://6b0bc6e8dce83e3eee5c7e654fbaca693730623fb7936a 1fd9d73de1a1dd8152 Image:registry.fjhb.cn/kubernetes-kube2sky Image id:docker-pullable://do      Cker.io/port/[email protected]:0230d3fbb0aeb4ddcf903811441cf2911769dbe317a55187f58ca84c95107ff5 Port:args: -kube_master_url=http://192.168.115.5:8080-domain=cluster.local limits:cpu:100m memory:50m          I requests:cpu:100m memory:50mi state:running Started: Tue, Jan 2018 10:55: 25-0500 ready:true Restart count:0 Volume Mounts:/var/run/secrets/kubernetes.io/servi Ceaccount from Default-token-6pddn (RO) environment Variables: <none> Skydns:container Id:docker ://ebc2aaaa54e2f922e370e454ec537665d813c69d37a21e3afd908e6dad056627 Image:registry.fjhb.cn/skydns Imag E id:docker-pullable://docker.io/skynetservices/[email protected]:6f8a9cff0b946574bb59804016d3aacebc637581 Bace452db6a7515fa2df79ee ports:53/udp, 53/tcp Args:-machines=http://127.0.0.1:4001-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, Jan 2018 10:55:27-0500 ready:true Restart count:0 Volume Mounts:/var/run/secrets/kubernete S.io/serviceaccount from DEFAULT-TOKEN-6PDDN (RO) environment Variables: <none> Healthz:container ID:DOCKER://F1DE1189FA           6b51281d414d7a739b86494b04c8271dc6bb5f20c51fac15ec9601 Image:registry.fjhb.cn/healthz Image ID: Docker-pullable://docker.io/wu1boy/[email protected]: d6690c0a8cc4f810a5e691b6a9b8b035192cb967cb10e91c74824bb4c8eea796 port:8080/tcp Args:-cmd=nslook    Up 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, 2018 10:55:29-0500 ready:true Restart count:0 Volume Mounts:/var/r Un/secrets/kubernetes.io/serviceaccount from Default-token-6pddn (RO) environment Variables: <none>condition S:type Status Initialized True ready True podscheduled TrUE Volumes:etcd-storage:type:emptydir (a temporary directory that shares a pod ' s lifetime) Medium:defaul T-token-6pddn:type:secret (a volume populated by a Secret) Secretname:default-token-6pddnqos Class:gu                   Aranteedtolerations: <none>events:firstseen lastseen Count from Subobjectpath Type Reason Message------------------------------ ------------------------------7m 7m 1 {default-schedule   R} 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{e   TCD} 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 wit H Docker ID 62AD76BFACA1 7m 7m 1 {kubelet 192.168.115.6} Spec.containers{kube2sky} No Rmal pulling pulling image "Registry.fjhb.cn/kubernetes-kube2sky" 7m 7m 1 {k Ubelet 192.168.115.6} Spec.containers{kube2sky} Normal Created Created container with Docker ID 6B0BC 6e8dce8; 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.1            68.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{skyd NS} 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 {Kub Elet 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


Iv. Modifying the Kubelet configuration file and restarting the service
Attention:
The--cluster-dns parameter is identical to the Clusterip parameter in the previous SVC file
The--cluster-domain parameter is identical to the-domain parameter in the previous RC file
All Kubelet nodes in the cluster need to be modified



# grep ‘KUBELET_ADDRESS‘ /etc/kubernetes/kubelet     KUBELET_ADDRESS="--address=192.168.115.5 --cluster-dns=10.254.16.254 --cluster-domain=cluster.local"# systemctl restart kubelet



V. Run a busybox and curl for testing



# cat busybox.yaml apiVersion: v1kind: Podmetadata:  name: busyboxspec:  containers:  - name: busybox    image: docker.io/busybox    command:    - sleep- "3600"

# cat curl.yaml apiVersion: v1kind: Podmetadata:  name: curlspec:  containers:  - name: curl    image: docker.io/webwurst/curl-utils    command:    - sleep- "3600"

# kubectl create -f busybox.yaml # kubectl create -f curl.yaml




The service of the kubernetes is parsed by the BusyBox container, and the service is automatically parsed into the corresponding cluster IP address, not the 172.16-segment Docker address.



# kubectl get svc# kubectl exec busybox -- nslookup frontend# kubectl exec busybox -- nslookup redis-master# kubectl exec busybox -- nslookup redis-slave




Access the previously created PHP message board via the Curl container



# kubectl exec curl -- curl frontend









Kubernetes Cluster Configuration DNS Service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.