k8s中的dns服务发现
一.dns服务
1.解决的问题
为了通过服务的名字在集群内进行服务相互访问,需要创建一个dns服务
2.k8s中使用的虚拟dns服务是skydns
二.搭建
1.创建并应用skydns-rc.yaml
[root@master dns]# cat skydns-rc.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kube-dns
namespace: kube-system
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
spec:
#指定副本数
replicas: 1
# replicas: not specified here:
# 1. In order to make Addon Manager do not reconcile this replicas parameter.
# 2. Default is 1.
# 3. Will be tuned in real time if DNS horizontal auto-scaling is turned on.
strategy:
rollingUpdate:
maxSurge: 10%
maxUnavailable: 0
selector:
matchLabels:
k8s-app: kube-dns
template:
metadata:
labels:
k8s-app: kube-dns
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ''
scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
spec:
containers:
- name: kubedns
image: docker.io/ist0ne/kubedns-amd64:latest
resources:
# TODO: Set memory limits when we've profiled the container for large
# clusters, then set request = limit to keep this container in
# guaranteed class. Currently, this container falls into the
# "burstable" category so the kubelet doesn't backoff from restarting it.
limits:
memory: 170Mi
requests:
cpu: 100m
memory: 70Mi
livenessProbe:
httpGet:
path: /healthz-kubedns
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /readiness
port: 8081
scheme: HTTP
# we poll on pod startup for the Kubernetes master service and
# only setup the /readiness HTTP server once that's available.
initialDelaySeconds: 3
timeoutSeconds: 5
args:
#指定一级域名
- --domain=rorshach.com.
- --dns-port=10053
- --config-map=kube-dns
#增加kube-master-url,指向k8s_master地址
- --kube-master-url=http://192.168.2.17:8080
# This should be set to v=2 only after the new image (cut from 1.5) has
# been released, otherwise we will flood the logs.
- --v=0
env:
- name: PROMETHEUS_PORT
value: "10055"
ports:
- containerPort: 10053
name: dns-local
protocol: UDP
- containerPort: 10053
name: dns-tcp-local
protocol: TCP
- containerPort: 10055
name: metrics
protocol: TCP
- name: dnsmasq
image: docker.io/ist0ne/k8s-dns-dnsmasq-amd64:latest
livenessProbe:
httpGet:
path: /healthz-dnsmasq
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
args:
- --cache-size=1000
- --no-resolv
- --server=127.0.0.1#10053
#注释掉
#- --log-facility=-
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
# see: https://github.com/kubernetes/kubernetes/issues/29055 for details
resources:
requests:
cpu: 150m
memory: 10Mi
- name: dnsmasq-metrics
image: docker.io/ist0ne/dnsmasq-metrics-amd64:latest
livenessProbe:
httpGet:
path: /metrics
port: 10054
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
args:
- --v=2
- --logtostderr
ports:
- containerPort: 10054
name: metrics
protocol: TCP
resources:
requests:
memory: 10Mi
- name: healthz
image: docker.io/ist0ne/exechealthz-amd64:latest
resources:
limits:
memory: 50Mi
requests:
cpu: 10m
# Note that this container shouldn't really need 50Mi of memory. The
# limits are set higher than expected pending investigation on #29688.
# The extra memory was stolen from the kubedns container to keep the
# net memory requested by the pod constant.
memory: 50Mi
args:
- --cmd=nslookup kubernetes.default.svc.huangzai.com 127.0.0.1 >/dev/null
- --url=/healthz-dnsmasq
- --cmd=nslookup kubernetes.default.svc.huangzai.com 127.0.0.1:10053 >/dev/null
- --url=/healthz-kubedns
- --port=8080
- --quiet
ports:
- containerPort: 8080
protocol: TCP
dnsPolicy: Default # Don't use cluster DNS.
2.创建并应用skydns-svc
[root@master dns]# cat 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
三.修改节点kubelet的参数
1.在/etc/kubernetes/kubelet文件中增加一下内容
--cluster_dns=10.254.0.100 --cluster_domain=rorshach.com
增加完后如下所示
KUBELET_ADDRESS="--address=0.0.0.0 --cluster_dns=10.254.0.100 --cluster_domain=rorshach.com"
2.重启kubelet服务
systemctl restart kubelet
四.测试
[root@master ingress]# kubectl exec -it nginx-deployment-3606461909-s69n6 -- nslookup mysql-service
nslookup: can't resolve '(null)': Name does not resolve Name: mysql-service
Address 1: 18.211.9.206 ec2-18-211-9-206.compute-1.amazonaws.com
因为上文中的rorshach.com是实际存在的域名,所以我们在master上通过hosts指定该域名
[root@master k8s]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.18 rorshach.com
再次测试:
[root@master k8s]# kubectl exec -it nginx-deployment-3606461909-s69n6 -- nslookup mysql-service
nslookup: can't resolve '(null)': Name does not resolve Name: mysql-service
Address 1: 10.254.12.207 mysql-service.default.svc.rorshach.com
已按预期呈现,现在我们就可以在应用程序中使用mysql-service这个服务名称来做host了
k8s中的dns服务发现的更多相关文章
- k8s DNS 服务发现的一个坑
按照官当文档,以及大家的实践进行k8s dns 服务发现搭建还是比较简单的,但是会有一个因为系统默认dns 配置造成的一个问题 1. linux 默认dns 配置在 /etc/resolv.conf ...
- Docker & k8s 系列三:在k8s中部署单个服务实例
本章将会讲解: pod的概念,以及如何向k8s中部署一个单体应用实例. 在上面的篇幅中,我们了解了docker,并制作.运行了docker镜像,然后将镜像发布至中央仓库了.然后又搭建了本机的k8s环境 ...
- 为什么亚马逊云计算中的DNS服务叫Route53?
最近在用亚马逊的云计算服务,看到它的DNS服务的名字叫做"Route 53".这个名字让我很好奇,为什么叫"Route 53"呢?有什么特殊含义? 看到了这个Q ...
- Ocelot中文文档-服务发现
Ocelot允许您指定服务发现提供程序,并使用它来查找Ocelot正在将请求转发给下游服务的主机和端口.目前,这仅在GlobalConfiguration部分中受支持,这意味着所有ReRoute将使用 ...
- Windows中的DNS服务——正向解析&反向解析配置 分类: AD域 Windows服务 2015-07-16 20:21 19人阅读 评论(0) 收藏
坚信并为之坚持是一切希望的原因. DNS服务是AD域不可或缺的一部分,我们在部署AD域环境时已经搭建了DNS服务(windows server 2008 R2域中的DC部署),但是DNS服务的作用还是 ...
- LINUX中的DNS服务---高速缓存DNS
一.什么是DNS Domain Name System,域名系统. 万维网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网.他主要负责把域名和IP的相互转换 ...
- LINUX中的DNS服务---DNS集群
一.DNS集群的理解 在使用DNS的时候,为了缓解服务器的压力,会使用多个辅助DNS服务器来分担主DNS的工作.这些DNS就叫做DNS集群. 二.配置过程 1)在辅DNS中操作如下:(主机号为172. ...
- LINUX中的DNS服务---DNS正向、反向和双向解析
一.DNS的正向解析 也就是域名解析为IP地址进行访问! 1)vim /etc/named.conf ----> 删除forwarders所在行 2)vim /etc/named.rf ...
- kubernetes 之dns 服务发现
1.在每个节点上面导入如下镜像 [root@node1 DNS]# lltotal 59816-rw-r--r--. 1 root root 8603136 Nov 25 18:13 execheal ...
随机推荐
- php漏洞tips
1.php后缀限制 'php,php3,php4,php5,php6,php7,phpsh,inc,phtml','PHT'; 2.php木马 <?php echo shell_exec($_G ...
- 1.L 查询关键字 HEXLOC
Take the compile listing for the program that has either OFFSET or LIST option selected. Use the OFF ...
- thinkphp结合bootstrap打造个性化分页
分页功能是web开发中常见的一项功能,也存在很多形式,这里主要讲一下利用thinkPHP框架的page类来打造一款bootstrap风格的分页过程. 首先需要去thinkPHP官网现在其分页扩展类ht ...
- DZY Loves Chinese / DZY Loves Chinese II
题面在这里! 这两个其实是一个题啦..双倍经验加成23333 可以很简单的发现如果把一条树边和所有覆盖它的非树边都删去的话,那么图会不连通: 如果再手玩一下可以发现,如果把两个被非树边覆盖的集合相同的 ...
- 【差分约束系统】【强连通分量缩点】【拓扑排序】【DAG最短路】CDOJ1638 红藕香残玉簟秋,轻解罗裳,独上兰舟。
题意: 给定n个点(点权未知)和m条信息:u的权值>=v的权值+w 求点权的极小解和极大解(无解则输出-1) 极小解即每个点的点权可能的最小值 极大解即每个点的点权可能的最大值 题解: 差分约束 ...
- 关于Mysort实验的补发博客
关于本次课后的一些话 关于这次课上的关于sort -nk 2 -t: sort.txt的实验没能在课上做出,有自身的知识不够,没能灵活运用所学知识,以及在当时课上走了会神,回过头来已经不知道该干些什么 ...
- python基础之re,sys,suprocess模块
re 正则表达式 1.什么是正则? 正则就是用一系列具有特殊含义的字符组成的规则,该规则用来描述具有某一特征的字符串. 正则就是用来在一个大的字符串匹配出符合规则的子字符串 2.为什么用正则? 正则可 ...
- Problem C: 指针:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面m个数
#include<stdio.h> int move(int *x,int n,int m) { ]; int i; //int *p;指针循环变量p ;i<n;i++) t[i]= ...
- ArrayList之扩容与迭代器
1. 扩容 ArrayList扩容包括ensureCapacity(对外开放)和ensureCapacityInternal(内部隐式调用)两个接口: 1' 两者都调用ensureExplicitCa ...
- React 16 升级时遇到的一个坑,分享一下
遇到的坑 今天在跟着dva.js官网上面的一个教程写东西的时候,照着教程上面的代码写之后,运行总是报错:TypeError: Cannot read property 'object' of unde ...