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. pandas 读写sql数据库

    如何从数据库中读取数据到DataFrame中? 使用pandas.io.sql模块中的sql.read_sql_query(sql_str,conn)和sql.read_sql_table(table ...

  2. python读取doc

    import os, time, fnmatch from docx import Document class search: def __init__(self, path, search_str ...

  3. libev 学习使用

    libev 简单的I/O库.  a high performance full featured event loop written in c libev 的大小也比 libevent 小得多并且自 ...

  4. Android 登录界面调用输入法时让界面自动上移,使输入法不会遮挡到主界面(Activity)

    先贴上效果图:   <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:andr ...

  5. Eclipse,myeclipse安装 配置Maven

    本文转自http://www.cnblogs.com/timeng/archive/2013/05/07/maven_install.html myeclipse自带了maven插件,但是和原生插件还 ...

  6. 使用vscode开发调试.net core应用程序并部署到Linux跨平台

    使用VS Code开发 调试.NET Core RC2应用程序,由于.NET Core 目前还处于预览版. 本文使用微软提供的示例进行开发及调试. https://github.com/aspnet/ ...

  7. Python的异步编程[0] -> 协程[0] -> 协程和 async / await

    协程 / Coroutine 目录 生产者消费者模型 从生成器到异步协程– async/await 协程是在一个线程执行过程中可以在一个子程序的预定或者随机位置中断,然后转而执行别的子程序,在适当的时 ...

  8. sed replace HEX sequence in your binary file:

    Here is how to replace a HEX sequence in your binary file: $ sed 's/\x0D\x4D\x53\x48/\x0D\x0A\x4D\x5 ...

  9. luogu P1802 5倍经验日

    题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却无奈的看着那一些比他等级高的好友,想着能否把他们干掉.干掉能拿不少经验的. 题目描述 现在absi2011拿出了x个迷你装药物 ...

  10. [BZOJ 2208] 连通数

    Link: BZOJ 2208 连通数 Solution: 传递闭包模板题 传递闭包是集合中最小的二元关系,其实就是对二元关系的不断拓展,一般用$floyd$求解 这里要先跑一遍$tarjan$求出$ ...