Kubernetes集群机制通过DNS进行服务名和ip的映射,如果没有配置dns,你可以通过下面命令查询到集群ip

kubectl get svc --namespace=kube-system

得到结果

但Cluster-ip是变化的,如果通过一个create命令一次批量建立一堆具有相互依赖关系的Pod或者RC,就需要配置DNS

配置DNS的方式有几种,我这里试通了最简单的一种SkyDNS的配置.

skydns-rc.yml

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:
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: gcr.io/google_containers/etcd-amd64:2.2.
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
#volumeMounts:
#- name: etcd-storage
# mountPath: /var/etcd/data
- name: kube2sky
- --domain=cluster.local
- --kube-master-url=http://192.168.0.105:8080
resources:
limits:
cpu: 100m
memory: 200Mi
requests:
cpu: 100m
memory: 50Mi
livenessProbe:
httpGet:
path: /healthz
port:
scheme: HTTP
initialDelaySeconds:
timeoutSeconds:
successThreshold:
failureThreshold:
readinessProbe:
httpGet:
path: /readiness
port:
scheme: HTTP
initialDelaySeconds:
timeoutSeconds:
args:
- --domain=cluster.local
- name: skydns
image: gcr.io/google_containers/skydns:---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:
- -ns-rotate=false
- -domain=cluster.local.
ports:
- containerPort:
name: dns
protocol: UDP
- containerPort:
name: dns-tcp
protocol: TCP
- name: healthz
image: gcr.io/google_containers/exechealthz:1.0
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=
ports:
- containerPort:
protocol: TCP
#volumes:
#- name: etcd-storage
# emptyDir: {}
dnsPolicy: Default

注意这里有个配置是指向你的api server

kube-master-url=http://192.168.0.105:8080

skydns-svc.yml

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.254.254
ports:
- name: dns
port:
protocol: UDP
- name: dns-tcp
port:
protocol: TCP

先去minion节点上下载所需要的images

docker pull gcr.io/google_containers/etcd-amd64:2.2.
docker pull gcr.io/google_containers/skydns:---8c72f8c
docker pull gcr.io/google_containers/exechealthz:1.0

然后运行构建

kubectl create -f skydns-rc.yml
kubectl create -f skydns-svc.yml

最后看到Pods处于Running状态

查看日志需要通过-c指定container name

[root@k8s-master skydns]# kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
kube-dns-v11-x0vr3 / Running 1d
[root@k8s-master skydns]# kubectl logs kube-dns-v11-x0vr3 -n kube-system
Error from server (BadRequest): a container name must be specified for pod kube-dns-v11-x0vr3, choose one of: [etcd kube2sky skydns healthz]
[root@k8s-master skydns]# kubectl logs kube-dns-v11-x0vr3 -n kube-system -c etcd
-- ::03.899264 I | etcdmain: etcd Version: 2.2.
-- ::03.899305 I | etcdmain: Git SHA: 75f8282
-- ::03.899310 I | etcdmain: Go Version: go1.5.1
-- ::03.899314 I | etcdmain: Go OS/Arch: linux/amd64
-- ::03.899319 I | etcdmain: setting maximum number of CPUs to , total number of available CPUs is
-- ::03.900546 I | etcdmain: listening for peers on http://localhost:2380
-- ::03.900607 I | etcdmain: listening for peers on http://localhost:7001
-- ::03.900626 I | etcdmain: listening for client requests on http://127.0.0.1:2379
-- ::03.900640 I | etcdmain: listening for client requests on http://127.0.0.1:4001
-- ::03.950602 I | etcdserver: name = default
-- ::03.950621 I | etcdserver: data dir = /var/etcd/data
-- ::03.950627 I | etcdserver: member dir = /var/etcd/data/member
-- ::03.950630 I | etcdserver: heartbeat = 100ms
-- ::03.950633 I | etcdserver: election = 1000ms
-- ::03.950637 I | etcdserver: snapshot count =
-- ::03.950649 I | etcdserver: advertise client URLs = http://127.0.0.1:2379,http://127.0.0.1:4001
-- ::03.950655 I | etcdserver: initial advertise peer URLs = http://localhost:2380,http://localhost:7001
-- ::03.950665 I | etcdserver: initial cluster = default=http://localhost:2380,default=http://localhost:7001
-- ::03.984118 I | etcdserver: starting member 6a5871dbdd12c17c in cluster f68652439e3f8f2a
-- ::03.984177 I | raft: 6a5871dbdd12c17c became follower at term
-- ::03.984194 I | raft: newRaft 6a5871dbdd12c17c [peers: [], term: , commit: , applied: , lastindex: , lastterm: ]
-- ::03.984198 I | raft: 6a5871dbdd12c17c became follower at term
-- ::03.984315 I | etcdserver: starting server... [version: 2.2., cluster version: to_be_decided]
-- ::03.997533 N | etcdserver: added local member 6a5871dbdd12c17c [http://localhost:2380 http://localhost:7001] to cluster f68652439e3f8f2a
-- ::04.785143 I | raft: 6a5871dbdd12c17c is starting a new election at term
-- ::04.785217 I | raft: 6a5871dbdd12c17c became candidate at term
-- ::04.785224 I | raft: 6a5871dbdd12c17c received vote from 6a5871dbdd12c17c at term
-- ::04.785245 I | raft: 6a5871dbdd12c17c became leader at term
-- ::04.785253 I | raft: raft.node: 6a5871dbdd12c17c elected leader 6a5871dbdd12c17c at term
-- ::04.785631 I | etcdserver: setting up the initial cluster version to 2.2
-- ::04.785697 I | etcdserver: published {Name:default ClientURLs:[http://127.0.0.1:2379 http://127.0.0.1:4001]} to cluster f68652439e3f8f2a
-- ::04.839450 N | etcdserver: set the initial cluster version to 2.2
[root@k8s-master skydns]#

好,dns配置完成!

Kubernetes DNS的配置的更多相关文章

  1. Kubernetes DNS安装配置

    #镜像在谷歌上需要FQ###################################下载kubernetes#DNS#cd kubernetes/cluster/addons/dns#修改tr ...

  2. Kubernetes DNS服务配置案例

    首先创建DNS服务的RC配置文件skydns-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: kube-dns-v ...

  3. Kubernetes DNS 简介

    环境 $ sudo lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16 ...

  4. Kubernetes DNS 高阶指南(转发别人 解析很详细)

    转发地址:http://www.jintiankansha.me/t/Js1R84GGAl DNS 是 Kubernetes 的核心功能之一,Kubernetes 通过 kube-dns 或  Cor ...

  5. Kubernetes ServiceAccount的配置

    开始配置Kubernetes集群的时候为了少出问题,都是在apiserver配置中去掉ServiceAccount采用非安全连接的方式,但在后面配置FEK日志的过程中,很多时候绕不开这个安全机制,但因 ...

  6. Linux DNS服务配置

    主.从域名服务器配置 一.实验环境 主域名服务器:ns1.topsec.com,192.168.120.119 从域名服务器:ns2.topsec.com,192.168.120.120 二.实验步骤 ...

  7. Linux系统下DNS主从配置详解

    一.DNS概述DNS(Domain Name System),即域名系统.因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串. ...

  8. centos DNS服务搭建 DNS原理 使用bind搭建DNS服务器 配置DNS转发 配置主从 安装dig工具 DHCP dhclient 各种域名解析记录 mydns DNS动态更新 第三十节课

    centos  DNS服务搭建  DNS原理  使用bind搭建DNS服务器 配置DNS转发 配置主从  安装dig工具  DHCP  dhclient  各种域名解析记录  mydns DNS动态更 ...

  9. 基于Bind实现的DNS正反向解析及主从DNS的配置

    一.什么是DNS? 1.1 简单的理解,Domain Name System,是互联网一项核心的服务,他作为一个桥梁可以将域名和IP地址相互因素的一个分布式数据库,能够使人更加方便的访问互联网,而不用 ...

随机推荐

  1. [BZOJ1024][SCOI2009]生日快乐解题报告

    Description windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕.现在包括windy,一共有 N 个人来分这块大蛋糕,要求每个人必须获得相同面积的蛋 ...

  2. 之江学院第0届校赛 qwb与支教 (容斥公式)

    description qwb同时也是是之江学院的志愿者,暑期要前往周边地区支教,为了提高小学生的数学水平.她把小学生排成一排,从左至右从1开始依次往上报数. 玩完一轮后,他发现这个游戏太简单了.于是 ...

  3. Codeforces Round #469 Div. 2 A B C D E

    A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...

  4. linux基础的基础命令操作

    一.开启Linux操作系统,要求以root用户登录GNOME图形界面,语言支持选择为汉语 操作:su - root 二.使用快捷键切换到虚拟终端2,使用普通用户身份登录,查看系统提示符 操作:ctrl ...

  5. python3,判断,循环练习1

    1.使用while循环输出1 2 3 4 5 6 8 9 10 i = 1 while i <= 10: if i == 7: i += 1 print(end=' ') continue pr ...

  6. KVM基本概念

    在kvm技术中,应用到的两个东西:qemu和kvm.其中kvm负责cpu虚拟化和内存虚拟化,但是kvm不能模拟其他设备,qemu是模拟IO设备(网卡,磁盘),kvm加上qemu之后就能实现真正意义上的 ...

  7. python中的迭代器详解

    #原创,转载请先联系 理论性的东西有点枯燥,耐心点看- 1.迭代是什么? 我们知道可以对list,tuple,dict,str等数据类型使用for...in的循环语法,从其中依次取出数据,这个过程叫做 ...

  8. lucene api

    设置重新打开索引目录(清空) IndexWriterConfig conf = new IndexWriterConfig(new WhitespaceAnalyzer());conf.setOpen ...

  9. 安装并启用rabbitmq服务器

    1.确保Erlang已经安装 2.安装rabbitmq服务器 [root@bogon yum.repos.d]# rpm --import https://dl.bintray.com/rabbitm ...

  10. 正则表达式、re、常用模块

    阅读目录 正则表达式 字符 量词 . ^ $ * + ? { } 字符集[][^] 分组 ()与 或 |[^] 转义符 \ 贪婪匹配 re 总结 正则 re 常用模块 namedtuple deque ...