搭建及使用K8s集群 <k8s Dns 部署>
2017-10-16 13:12
896 查看
k8s Dns 部署
k8s Dns 部署k8s dns 相关镜像准备
修改配置文件
1 修改各个node上的kubelet
2 修改APIserver
yamls 编写
1 skydns-rcyml
2 skydns-svcyaml
创建pods
验证k8s dns
1 部署busybox
2 nslookup 验证
1. k8s dns 相关镜像准备
2. yamls 编写
3. 创建pod service
4. 验证k8s dns
docker 容器的ip 是动态的,多个服务之间没法通讯,k8s dns 解决了该问题,访问不通过ip,通过app name 进行访问。
1. k8s dns 相关镜像准备
百度一把 文章都是google的镜像,国内pull不下来,可以去dockerhub上搜到的对应版本,tag & push到个人的dockerhub下镜像 | 版本 |
---|---|
docker.io/cdchen/etcd | 2.0.9 |
docker.io/cdchen/kube2sky | 1.11 |
docker.io/cdchen/skydns | 2015-03-11-001 |
2. 修改配置文件
2.1 修改各个node上的kubelet
[root@node2 ~]# cat /etc/kubernetes/kubelet ### # kubernetes kubelet (minion) config # The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces) KUBELET_ADDRESS="--address=0.0.0.0" # The port for the info server to serve on KUBELET_PORT="--port=10250" # You may leave this blank to use the actual hostname KUBELET_HOSTNAME="--hostname-override=node2" # location of the api-server KUBELET_API_SERVER="--api-servers=http://master:8080" # pod infrastructure container KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest" # Add your own! KUBELET_ARGS=" --cluster_dns=10.254.0.2 --cluster_domain=atomic.io "
2.2 修改APIserver
[root@master yamls]# cat /etc/kubernetes/apiserver ### # kubernetes system config # # The following values are used to configure the kube-apiserver # # The address on the local server to listen to. KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" # The port on the local server to listen on. KUBE_API_PORT="--port=8080" # Port minions listen on # KUBELET_PORT="--kubelet-port=10250" # Comma separated list of nodes in the etcd cluster KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379" # Address range to use for services KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" # default admission control policies KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota" # Add your own!
比对下 KUBE_ADMISSION_CONTROL内容
重启 Master 和 各Node 服务
3. yamls 编写
3.1 skydns-rc.yml
apiVersion: v1 kind: ReplicationController metadata: name: kube-dns-v6 namespace: default labels: k8s-app: kube-dns version: v6 kubernetes.io/cluster-service: "true" spec: replicas: 1 selector: k8s-app: kube-dns version: v6 template: metadata: labels: k8s-app: kube-dns version: v6 kubernetes.io/cluster-service: "true" spec: containers: - name: etcd image: docker.io/cdchen/etcd:2.0.9 command: - /usr/local/bin/etcd - -listen-client-urls - http://0.0.0.0:2379,http://0.0.0.0:4001 - -advertise-client-urls - http://127.0.0.1:2379,http://127.0.0.1:4001 - -initial-cluster-token - skydns-etcd - name: kube2sky image: docker.io/cdchen/kube2sky:1.11 resources: limits: cpu: 100m memory: 50Mi command: - /kube2sky - --kube_master_url=http://192.168.6.45:8080 - -domain=atomic.io - name: skydns image: docker.io/cdchen/skydns:2015-03-11-001 resources: command: - /skydns - -machines=http://localhost:4001 - -addr=0.0.0.0:53 - -domain=atomic.io. ports: - containerPort: 53 name: dns protocol: UDP - containerPort: 53 name: dns-tcp protocol: TCP dnsPolicy: Default
3.2 skydns-svc.yaml
apiVersion: v1 kind: Service metadata: name: kube-dns namespace: default labels: k8s-app: kube-dns kubernetes.io/cluster-service: "true" kubernetes.io/name: "KubeDNS" spec: selector: k8s-app: kube-dns clusterIP: 10.254.0.2 ports: - name: dns port: 53 protocol: UDP - name: dns-tcp port: 53 protocol: TCP
4 创建pods
[root@master sky_dns]# kubectl create -f skydns-rc.yml replicationcontroller "kube-dns-v6" created [root@master sky_dns]# kubectl create -f skydns-svc.yaml service "kube-dns" created [root@master sky_dns]# kubectl get pods NAME READY STATUS RESTARTS AGE cloud-eureka-server-1593312766-cx7w8 1/1 Running 0 2h kube-dns-v6-5tf2j 3/3 Running 0 1m
5 验证k8s dns
5.1 部署busybox
[root@master yamls]# cat busybox.yaml apiVersion: v1 kind: Pod metadata: name: busybox namespace: default spec: containers: - image: busybox command: - sleep - "3600" imagePullPolicy: IfNotPresent name: busybox restartPolicy: Always [root@master yamls]# kubectl create -f busybox.yaml pod "busybox" created
3.2 nslookup 验证
[root@master yamls]# kubectl exec busybox -it sh [root@master ~]# kubectl exec busybox -it sh / # nslookup cloud-eureka-server Server: 10.254.0.2 Address 1: 10.254.0.2 Name: cloud-eureka-server Address 1: 10.254.247.31 / #
解析成功,其中 cloud-eureka-server 是我部署的一个springcloud 应用。
相关文章推荐
- 搭建及使用K8s集群 <k8s 集群部署springcloud 多应用>
- 搭建及使用K8s集群 <k8s集群部署springcloud 单应用>
- 搭建及使用K8s集群 <简介>
- 搭建及使用K8s集群 <k8s dashboard pod方式部署>
- 搭建及使用K8s集群 <k8s集群搭建>
- 搭建及使用K8s集群 <使用ingress 暴露springcloud服务>
- 搭建及使用K8s集群 <目录>
- Kubernetes(三) - 使用Rancher部署K8S集群(搭建Kubernetes)
- Kubernetes(二) - 使用Rancher部署K8S集群(搭建Rancher)
- CentOS7.2中使用Kubernetes(k8s)1.4.6源码搭建k8s容器集群环境
- 使用sqlserver搭建高可用双机热备的Quartz集群部署【附源码】
- <转>android-滑动菜单栏-开源项目SlidingMenu的搭建和使用
- Storm集群安装部署步骤【详细版】<转>
- 使用SpringCloud搭建微服务<三>---------使用EureKa编写服务的注册中心
- 一步一图搭建-分布式服务器部署之mysql集群-使用amoeba整合mysql实现读写分离
- Python <Windows 使用Django 搭建第一个web项目 1>
- 使用jenkins、docker、consul、nginx搭建支持自动化构建部署以及弹性伸缩的集群系统详细教程
- Hadoop 三台主机 集群搭建 详解 &lt;转&gt;
- 使用docker搭建部署hadoop分布式集群
- 使用Ambari来部署hadoop集群(搭建内网HDP源)