Troubleshooting of k8s implementation problems in the development and testing environment-internal network DNS resolution

Source: Internet
Author: User
Tags k8s
I believe many of my friends have already used k8s in the testing or production environment to solve their own business problems. The following are some of our practices in the testing environment. We direct all services and pods to developers and testers (without ingress, nodeport, and lb, we directly use Static Routing + NAT ), in this way, our testing and developers can directly access SVC and pod. We will discuss it separately later. Most of us are mobile native developers, so most of us need to use WiFi + DNS servers to test our apps. However, if there are many Intranet sites and many services, you need to maintain the DNS server frequently. Can you automatically maintain our DNS server based on our service.

Ideas:
1. obtain all services under all namespaces in the k8s container cloud, and set rules. For example, all web services use the complete domain name as the service name, for example, in api.abc.com, the service name is API-ABC-com, and Kube-system is filtered out.
2. Write the obtained namespace, domain name, And clusterip to the DNS configuration file in the corresponding folder. If yes, delete the file and add it. If no, add it automatically.
3. Load the DNS configuration files for each namespace

#!/bin/bashsvc=$(kubectl get svc --all-namespaces|awk ‘/-/ && NR!=1 && !/kube-system/ {print $1,$2,$4}‘|sed ‘s#-#.#g‘)echo "$svc"|while read linedo        namespace=`echo $line|awk ‘{print $1}‘`        [ -d $namespace ] || mkdir -p ${namespace}        [ -f ${namespace}/dns ] || touch ${namespace}/dns        domain=`echo $line|awk ‘{print $2}‘`        dns_record=`echo $line|awk ‘{print $2"="$3}‘`        [ `grep ${dns_record} ${namespace}/dns|wc -l` ] && sed -i "/${domain}/d" ${namespace}/dns && echo ${dns_record}>>${namespace}/dns        names=`cat ${namespace}/dns | grep -v ‘^#|^//‘ | tr ‘\n‘ ‘,‘|sed ‘s/,$//g‘`        sed "s#{namespace}#${namespace}#g" ~/yaml/dns/deploy.yaml | sed "s#{names}#${names}#g"|kubectl apply -f -done

View the deploy-svc.yaml of DNS

Apiversion: extensions/v1beta1kind: deploymentmetadata: Name: DNS namespace: {namespace} SPEC: selector: matchlabels: Name: DNS replicas: 1 template: Metadata: labels: Name: dns spec: containers:-Name: bind image: cytopia/Bind ports:-containerport: 53 Protocol: TCP name: dnstcp-containerport: 53 Protocol: UDP name: dnsudp env:-Name: extra_hosts value: "{names}"-Name: dns_forwarder value: "114.114.114.144, 8.8.4.4" # This is an Internet DNS server --- apiversion: v1kind: servicemetadata: Name: DNS namespace: {namespace} labels: Name: dnsspec: ports:-Protocol: TCP port: 53 targetport: 53 name: dnstcp-Protocol: UDP port: 53 targetport: 53 name: dnsudp selector: name: DNS

Troubleshooting of k8s implementation problems in the development and testing environment-internal network DNS resolution

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.