Kubernetes Cluster Deployment DNS Service

Source: Internet
Author: User
Tags nslookup etcd k8s

Kubernetes service

Kubernetes Cluster Deployment DNS Service
In Kubernetes each service will be assigned a virtual IP, each service under normal circumstances will not change for a long time, this is relative to the pod of the indefinite IP, the use of the cluster app is relatively stable.


Kubernetes cpu limit


kubernetes service pod

But the service's information injected into the pod is currently using an environment variable, and relies heavily on pod (RC) and service creation order, which makes the cluster look less perfect, so kubernetes introduced the DNS system in a plug-in way. Using DNS to map the service so that we can use the domain name directly in the app to reference, avoid the previous variable flooding problem, but also avoid the embarrassing situation of the creation order.

Kubernetes cpu memory limits

Kubernetes as service

Component: cpu limit kubernetes 
? SKYDNS provides DNS resolution service
? ETCD Storing DNS information
? Kube2sky Monitor Kubernetes, when a service is created, generate corresponding records to Skydns


Kubernetes cpu limit 0

1. Download the Create DNS Mirror (node node download)
Docker pull docker.gaoxiaobang.com/kubernetes/etcd-amd64:2.2.1
Docker pull docker.gaoxiaobang.com/kubernetes/kube2sky:1.14
Docker Pull Docker.gaoxiaobang.com/kubernetes/skydns : 2015-10-13-8c72f8c
Docker pull docker.gaoxiaobang.com/kubernetes/exechealthz:1.0

Kubernetes as a service
2. Create a namespace
According to the namespace divided into different namespaces, the system services unified into a separate space: Kube-system, kubernetes cpu limits vs requests,because the default space is only defaulted, we first want to create Kube-system space.
Vim Kube-system.yaml with the following contents:
Apiversion:v1
Kind:namespace
Metadata: selector kubernetes service
Name:kube-system

Cpu requests and limits kubernetes

Kubernetes expose service port

3. Edit the Replicationcontroller file on the master server
Vim Skydns-rc.yaml, as follows, remember to modify the Red Font section:
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:docker.gaoxiaobang.com/kubernetes/etcd-amd64:2.2.1
    Resources
    Limits
    cpu:100m
    Memory:500mi
    Requests:
    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
  • Name:kube2sky
    image:docker.gaoxiaobang.com/kubernetes/kube2sky:1.14
    Args
    • --domain=cluster.local
    • --kube-master-url=http://192.168.1.10:8080
      Resources
      Limits
      cpu:100m
      Memory:200mi
      Requests:
      cpu:100m
      Memory:50mi
  • Name:skydns
    image:docker.gaoxiaobang.com/kubernetes/skydns:2015-10-13-8c72f8c
    Resources:
    Limits:
    cpu:100m
    Memory:200mi
    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
      Protoc OL:TCP
      Livenessprobe:
      HttpGet:
      Path:/healthz
      port:8080
      scheme:http
      initialdelayseconds:60
      Timeoutseconds:5
      successthreshold:1
      failurethreshold:5
      Readinessprobe:
      HttpGet:
      Path:/ Readiness
      port:8080
      scheme:http
      initialdelayseconds:30
      timeoutseconds:5
  • Name:healthz
    image:docker.gaoxiaobang.com/kubernetes/exechealthz:1.0
    Resources
    Limits
    cpu:10m
    Memory:20mi
    Requests:
    cpu:10m
    Memory:20mi
    Args
    • -cmd=nslookup kubernetes.default.svc.cluster.local localhost >/dev/null
    • -port=8080
      Ports
    • containerport:8080
      Protocol:tcp
      Volumes
  • Name:etcd-storage
    Emptydir: {}
    Dnspolicy:default


4. Create the Skydns service file on Master Skydns-service.yaml
before you create SKYDNS-SERVICE.YAML, you need to manually specify a CLUSTER-IP
for DNS you need to view your/etc /kubernetes/apiserver files and kubernetes cluster-ip:
[[email protected] dns]# Cat/etc/kubernetes/apiserver | grep kube_service_addresses
kube_service_addresses= "--service-cluster-ip-range=172.25.0.0/24"
[[email  protected] dns]# kubectl Get service
NAME TYPE cluster-ip external-ip PORT (S) Age
Kubernetes Clusterip 172.25 .0.1 <none> 443/tcp 19d
If the two IP addresses belong to the same network segment, pick an IP from 172.25.0.0 to act as the cluster-ip of the DNS;
if not, In the Kubernetes Cluster-ip, modify the Apiserver network address range, restart Apiserver, and then pick an IP from 172.25.0.0 as DNS Cluster-ip



Create the Skydns-service.yaml file, notice the change in the Red section, here I choose the Dns-clusterip is 172.25.0.254
Vim Skydns-service.yaml, the content is as follows:
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:172.25.0.254
Ports


    • Name:dns
      port:53
      Protocol:udp
    • Name:dns-tcp
      port:53
      Protocol:tcp


5. Create a Cluster-dns analytic application in the cluster
? Create namespace
Kubectl create-f Kube-system.yaml



? Create Replicationcontroller
Kubectl create-f Skydns-rc.yaml



? Create service
Kubectl create-f Skydns-service.yaml



Delete is to replace "create" in the above three commands with "delete"
6. View the startup status of the Dns-pod
[[email protected] k8s-master dns]# kubectl get pod--namespace=kube-system
NAME Ready STATUS Restarts
kube-dns-v11-ey14j 4/4 Running 8 1d
7. View the information for the service defined in the Skydns-service.yaml file.
[[email protected] k8s-master dns]# kubectl Get Svc--namespace=kube-system
NAME cluster-ip external-ip PORT (S) Age
Kube-dns 172.25.0.254 <none> 53/udp,53/tcp 1d



8. Testing DNS Functionality
(1) Get BusyBox image
Docker Pull Busybox:latest
(2) Edit the Yaml file of the BusyBox pod
Vim Busybox.yaml, the content is as follows:
Apiversion:v1
Kind:pod
Metadata
Name:busybox
Namespace:default
Spec
Containers


    • Image:busybox:latest
      Command
      • Sleep
      • "3600"
        Imagepullpolicy:ifnotpresent
        Name:busybox
        Restartpolicy:always


(3) Create a busybox pod:
Kubectl create-f Busybox.yaml
Pod Boot status:
[[email protected] dns]# Kubectl get pods
NAME Ready STATUS Restarts
BusyBox 1/1 Running 2 2h



(4) test DNS with BusyBox-nslookup
After the Kubernetets cluster is built, there will be a default CLUSTER-IP, which can be viewed by command:
[[email protected] dns]# Kubectl Get services
NAME TYPE cluster-ip external-ip PORT (S) Age
Kubernetes clusterip 172.25.0.1 <none> 443/tcp 19d



To start the test, the parsing time may be a little long and wait patiently:
[Email protected] dns]# kubectl exec busybox nslookup kubernetes.default
server:172.25.0.254
Address 1:172.25.0.254



Name:kubernetes.default
Address 1:172.25.0.1



Parse success, note, The Kubernetes.default parameter above, Kubernetes is the default namespace of k8s for the service Name,default, if you are not querying the domain name in the default namespace, change the default, for example:
[[email protected] dns]# Kubectl get service-n Kube-system
NAME TYPE cluster-ip external-ip PORT (S) Age
Kube-dns clusterip 172.25.0.254 <none> 53/udp,53/tcp 2h
If you want to resolve the IP of the domain name "Kube-dns", you need to write this:
[Email protected] dns]# kubectl exec busybox nslookup kube-dns.kube-system
server:172.25.0.254
Address 1:172.25.0.254



Name:kube-dns.kube-system
Address 1:172.25.0.254



At this point, Kubernetes's DNS was built successfully



Kubernetes Cluster Deployment DNS Service


Related Article

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.