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. [BZOJ1010][HNOI2008]玩具装箱toy 解题报告

    Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...

  2. [BZOJ1004] [HNOI2008]Cards解题报告(Burnside引理)

    Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有多少种染色方案,Sun很快就给出了答案.进一步,小春要求染出Sr张红 ...

  3. bzoj 3223 裸splay

    裸的splay 今儿写的splay,由于自己刚开始学,发现几个容易漏掉的地方 1:开始给所有的儿子赋值为-1 2:给max[-1]赋值为-maxlongint 3:开始father[root]:=sr ...

  4. Django-Django的form表单

    注册页面如果用ajax来做,视图views里面判断会很复杂,需要判断各种字段,我们用form来做   form_obj,实例化form_post(form_obj)对象,一定要加上(request.P ...

  5. GCC编译安装

    1. 安装静态库,如果没有安装静态库,后面编译不会通过: yum install glibc-static libstdc++-static -y 2. 下载GCCxxx.tat.gz: wget h ...

  6. java对象内存大小评估

    Java对象的内存布局:对象头(Header).实例数据(Instance Data)和对齐填充(Padding).无论是32位还是64位的HotSpot,使用的都是8字节对齐.也就是说每个java对 ...

  7. Linux中inet_aton的问题(IP转整数)

    在网上看到一篇如下文章: 原题目是说的mysql的陷阱,但是仔细分析起来,应该是Linux,c在转换的时间的问题,不符合ip串转整形的通用算法,所以用c转的时候还需注意 linux C中有个函数ine ...

  8. JavaScript变量、数据类型、函数

    #转载请留言联系 说在前面: JavaScript 是一种弱类型语言,javascript的变量类型由它的值来决定. JavaScript语句的末尾用 ; 结束.空格没有特殊意义. 1.JavaScr ...

  9. NetBeans中从实体创建Restful webservice工程

    分布式系统和移动计算...... 这学期上的课,名字听起来是不是很霸气? 然而 其实就是 restful 和 安卓...... 汗....... 用的IDE还是netBeans, 第一次听说有这个ID ...

  10. 百度Map-JSAPI-覆盖物范围查询标记

    1.单点标记并添加说明信息 2.可视化区域范围 3.矩形覆盖物经纬度范围 说明:该项目为javaweb项目,标记点信息为数据库中存储信息] 参考API链接 http://api.map.baidu.c ...