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. Linux rar乱码

    大家都知道,Linux下的中文乱码是一个很烦的事情,在这里我叫大家如何解决这个问题. rar乱码 ubunut下打开rar包,如果里面有中文就会显示乱码,其实就觉这个问题最简单了,只要把进入新立得,搜 ...

  2. v4l2 Camera详细设置【转】

    转自:http://blog.csdn.net/smilefyx/article/details/39555289 转载自:http://blog.sina.com.cn/s/blog_602f877 ...

  3. selenium 多表单切换处理(iframe/frame)

    在web应用中,前台网页的设计一般会用到iframe/frame表单嵌套页面的应用.简单的就是一个页面签嵌套多个HEML/JSP文件.selenium webdriver  只能在同一页面识别定位元素 ...

  4. poj 2007(凸包)

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8005   Accepted: 3798 ...

  5. 【UOJ UNR #1】火车管理 可持久化线段树

    用可持久化线段树维护每个站的第一辆车和每个站的前一次更新的位置即可. #include<iostream> #include<cstring> #include<cstd ...

  6. Unable to set localhost. This prevents creation of a GUID

    原因:tomcat无法解析hostname 解决方案:解决方案:在/etc/hosts文件中添加hostname解析

  7. POJ 3264.Balanced Lineup-结构体版线段树(区间查询最值)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 53721   Accepted: 25244 ...

  8. 修改hadoop的jar包运行时候分配的jvm内存

    在hadoop-env.sh中修改参数添加 export HADOOP_HEAPSIZE="4096" 设置分配的最大jvm内存为4096,一般用于jar包里面除了执行map和re ...

  9. 百度之星资格赛 2016 Problem 1002

    本文链接:http://www.cnblogs.com/Ash-ly/p/5494623.html 题意: 度熊面前有一个全是由1构成的字符串,被称为全1序列.你可以合并任意相邻的两个1,从而形成一个 ...

  10. 模板—数学—Exgcd

    模板—数学—Exgcd Code: #include <cstdio> #include <algorithm> using namespace std; int ex_gcd ...