1.1.部署K8S内网资源清单http服务

1.2.部署coredns

部署K8S内网资源清单http服务

在运维主机HDSS7-200.host.com上,配置一个nginx虚拟主机,用以提高k8s统一的资源配置清单访问入口

  • 配置nginx
[root@hdss7- ~]# vi /etc/nginx/conf.d/k8s-yaml.fx.com.conf
server {
listen ;
server_name k8s-yaml.fx.com; location / {
autoindex on;
default_type text/plain;
root /data/k8s-yaml;
}
}
[root@hdss7- ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@hdss7- ~]# nginx -s reload
[root@hdss7- ~]# cd /data
[root@hdss7- data]# mkdir k8s-yaml
[root@hdss7- data]# cd k8s-yaml/
[root@hdss7- k8s-yaml]# mkdir coredns
[root@hdss7- k8s-yaml]#
  • 配置dns解析
[root@hdss7- ~]# vi /var/named/fx.com.zone
$ORIGIN fx.com.
$TTL ; minutes
@ IN SOA dns.fx.com. dnsadmin.fx.com. (
; serial
; refresh ( hours)
; retry ( minutes)
; expire ( week)
; minimum ( day)
)
NS dns.fx.com.
$TTL ; minute
dns A 10.4.7.11
harbor A 10.4.7.200
k8s-yaml A 10.4.7.200
[root@hdss7- ~]# systemctl restart named
[root@hdss7- ~]# dig -t A k8s-yaml.fx.com @10.4.7.11 +short
10.4.7.200

下载coredns(docker)镜像并打包上传到harbor仓库

[root@hdss7- k8s-yaml]# docker pull coredns/coredns:1.6.
[root@hdss7- k8s-yaml]# docker tag c0f6e815079e harbor.fx.com/public/coredns:v1.6.1
[root@hdss7- k8s-yaml]# docker push harbor.fx.com/public/coredns:v1.6.1

准备资源配置清单

[root@hdss7- ~]#  mkdir -p /data/k8s-yaml/coredns && cd /data/k8s-yaml/coredns/
  • rbac.yaml
[root@hdss7- coredns]# vi rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: coredns
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
kubernetes.io/bootstrapping: rbac-defaults
addonmanager.kubernetes.io/mode: Reconcile
name: system:coredns
rules:
- apiGroups:
- ""
resources:
- endpoints
- services
- pods
- namespaces
verbs:
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
addonmanager.kubernetes.io/mode: EnsureExists
name: system:coredns
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:coredns
subjects:
- kind: ServiceAccount
name: coredns
namespace: kube-system
  • configmap.yaml
[root@hdss7- coredns]# vi cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.: {
errors
log
health
ready
kubernetes cluster.local 192.168.0.0/
forward . 10.4.7.11
cache
loop
reload
loadbalance
}
  • dp.yaml
[root@hdss7- coredns]# vi dp.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: coredns
namespace: kube-system
labels:
k8s-app: coredns
kubernetes.io/name: "CoreDNS"
spec:
replicas:
selector:
matchLabels:
k8s-app: coredns
template:
metadata:
labels:
k8s-app: coredns
spec:
priorityClassName: system-cluster-critical
serviceAccountName: coredns
containers:
- name: coredns
image: harbor.fx.com/public/coredns:v1.6.1
args:
- -conf
- /etc/coredns/Corefile
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
ports:
- containerPort:
name: dns
protocol: UDP
- containerPort:
name: dns-tcp
protocol: TCP
- containerPort:
name: metrics
protocol: TCP
livenessProbe:
httpGet:
path: /health
port:
scheme: HTTP
initialDelaySeconds:
timeoutSeconds:
successThreshold:
failureThreshold:
dnsPolicy: Default
volumes:
- name: config-volume
configMap:
name: coredns
items:
- key: Corefile
path: Corefile
  • svc.yaml
[root@hdss7- coredns]# vi svc.yaml
apiVersion: v1
kind: Service
metadata:
name: coredns
namespace: kube-system
labels:
k8s-app: coredns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "CoreDNS"
spec:
selector:
k8s-app: coredns
clusterIP: 192.168.0.2
ports:
- name: dns
port:
protocol: UDP
- name: dns-tcp
port:
- name: metrics
port:
protocol: TCP

 应用资源配置清单

[root@hdss7- ~]# kubectl apply -f http://k8s-yaml.fx.com/coredns/rbac.yaml
serviceaccount/coredns created
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
[root@hdss7- ~]# kubectl apply -f http://k8s-yaml.fx.com/coredns/cm.yaml
configmap/coredns created
[root@hdss7- ~]# kubectl apply -f http://k8s-yaml.fx.com/coredns/dp.yaml
deployment.apps/coredns created
[root@hdss7- ~]# kubectl apply -f http://k8s-yaml.fx.com/coredns/svc.yaml
service/coredns created
[root@hdss7- ~]# kubectl get all -n kube-system
NAME READY STATUS RESTARTS AGE
pod/coredns-65cb567d6f-4x5tn / Running 32s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/coredns ClusterIP 192.168.0.2 <none> /UDP,/TCP,/TCP 26s NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/coredns / 32s NAME DESIRED CURRENT READY AGE
replicaset.apps/coredns-65cb567d6f 32s

验证coredns

[root@hdss7- ~]# dig -t A www.baidu.com @192.168.0.2 +short
www.a.shifen.com.
220.181.38.150
220.181.38.149
[root@hdss7- ~]# kubectl get svc -n kube-public
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-dp ClusterIP 192.168.164.107 <none> /TCP 28h
[root@hdss7- ~]# dig -t A nginx-dp.kube-public.svc.cluster.local. @192.168.0.2 +short
192.168.164.107
[root@hdss7- ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-ds-ffw5x / Running 3h48m 172.7.22.2 hdss7-.host.com <none> <none>
nginx-ds-t2scb / Running 3h47m 172.7.21.2 hdss7-.host.com <none> <none>
[root@hdss7- ~]# kubectl exec -it nginx-ds-ffw5x /bin/bash
root@nginx-ds-ffw5x:/# curl nginx-dp.kube-public
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>

4.kubernetes的服务发现插件-CoreDNS的更多相关文章

  1. 十一章 Kubernetes的服务发现插件--coredns

    1.前言 简单来说,服务发现就是服务(应用)之间相互定位的过程: 服务发现并非云计算时代独有的,传统的单体架构时代也会用到,以下应用场景更加需要服务发现: 服务(应用)的动态性强: 服务(应用)更新发 ...

  2. Istio技术与实践02:源码解析之Istio on Kubernetes 统一服务发现

    前言 文章Istio技术与实践01: 源码解析之Pilot多云平台服务发现机制结合Pilot的代码实现介绍了Istio的抽象服务模型和基于该模型的数据结构定义,了解到Istio上只是定义的服务发现的接 ...

  3. 第十二章 Kubernetes的服务暴露插件--traefik

    1.前言 之前部署的coredns实现了k8s的服务在集群内可以被自动发现,那么如何使得服务在k8s集群外被使用和访问呢? 使用nodeport星的Service:此方法只能使用iptables模型, ...

  4. Kubernetes之服务发现及负载Services

    Service 概述 kubernetes 中的pod是有生生灭灭的,时刻都有可能被新的pod所代替,而不可复活(pod的生命周期).一旦一个pod生命终止,通过ReplicaSets动态创建和销毁p ...

  5. 5.kubernetes的服务暴露插件-Traefik

    目录 1.部署traefik 2.准备资源配置清单 3.应用资源配置清单 4.检查创建资源 5.解析域名 6.配置反向代理 7.浏览器访问 部署traefik 在HDSS7-200.host.com上 ...

  6. K8S(04)核心插件-coredns服务

    K8S核心插件-coredns服务 目录 K8S核心插件-coredns服务 1 coredns用途 1.1 为什么需要服务发现 2 coredns的部署 2.1 获取coredns的docker镜像 ...

  7. Prometheus在Kubernetes下的服务发现机制

    Prometheus作为容器监控领域的事实标准,随着以Kubernetes为核心的云原生热潮的兴起,已经得到了广泛的应用部署.灵活的服务发现机制是Prometheus和Kubernetes两者得以连接 ...

  8. Docker与k8s的恩怨情仇(七)—— “服务发现”大法让你的内外交互原地起飞

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 第一章:Docker与k8s的恩怨情仇(一)-成为PaaS前浪的Cloud Foundry 第二章:Dock ...

  9. 基于 Consul 的 Docker Swarm 服务发现

    Docker 是一种新型的虚拟化技术,它的目标在于实现轻量级操作系统的虚拟化.相比传统的虚拟化方案,Docker 虚拟化技术有一些很明显的优势:启动容器的速度明显快于传统虚拟化技术,同时创建一台虚拟机 ...

随机推荐

  1. unicode 的中文字符串,调用 isalnum()返回的是 True ?

    描述 Python isalnum() 方法检测字符串是否由字母和数字组成. 语法 isalnum()方法语法: str.isalnum() 返回值 如果 string 至少有一个字符并且所有字符都是 ...

  2. [C# WPF] 根据按钮动态跳转窗体

    WPF 根据按钮动态跳转窗体 XMAL文件中,用Tag保存要跳的页面 <Button Name="btnWindow01" Content="ClickMe&quo ...

  3. JVM调优总结(四)-分代垃圾回收详述

    为什么要分代 分代的垃圾回收策略,是基于这样一个事实:不同的对象的生命周期是不一样的.因此,不同生命周期的对象可以采取不同的收集方式,以便提高回收效率. 在Java程序运行的过程中,会产生大量的对象, ...

  4. 接口(interface)的使用

    类实现接口就具有接口的功能 实现可以多实现,实现多个接口 package cm.aff.abst; /* 接口(interface)是与类并行的一个概念 1. 接口可以看做是一个特殊的抽象类,是常量与 ...

  5. Linux实验

    实验一 Linux系统安装与简单配置 一.实验目的 1.掌握Linux系统安装的分区准备. 2.掌握Linux系统的安装步骤. 3.掌握Linux系统分区的挂载和卸载. 4.掌握Linux系统的启动和 ...

  6. 前端基础知识之html和css全解

    前端回顾 目录 前端回顾 基础知识 HTTP协议 认识HTML HTML组成 HTML标签 div和span标签 特殊的属性 常用标签 认识css 选择器 属性 前端就是展示给用户并且与用户进行交互的 ...

  7. 01 . RabbitMQ简介及部署

    RabbitMQ简介 ​ MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它 ...

  8. 北京理工大学复试上机--2001B

    1.请输入高度 h,输入一个高为 h,上底边长为 h的等腰梯形(例如 h=4,图形如下).    ****   ******  ******** ********** #include <ios ...

  9. Bootstrap解决页面缩小变形的办法

    bootstrap布局是应用得很广泛的一种网页布局方法,例如:我们用一种中间内容很流行的布局分布:3-6-3式布局.代码如下 <style type="text/css"&g ...

  10. Dubbo源码笔记-服务注册

    今天来简单做一下Dubbo服务注册部分源码学习手记. 一.Dubbo配置解析 目前Dubbo最多的用法就是跟Spring集成,既然跟Spring集成,那么,Dubbo对象的实例化都将交由Spring统 ...