4.kubernetes的服务发现插件-CoreDNS
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的更多相关文章
- 十一章 Kubernetes的服务发现插件--coredns
1.前言 简单来说,服务发现就是服务(应用)之间相互定位的过程: 服务发现并非云计算时代独有的,传统的单体架构时代也会用到,以下应用场景更加需要服务发现: 服务(应用)的动态性强: 服务(应用)更新发 ...
- Istio技术与实践02:源码解析之Istio on Kubernetes 统一服务发现
前言 文章Istio技术与实践01: 源码解析之Pilot多云平台服务发现机制结合Pilot的代码实现介绍了Istio的抽象服务模型和基于该模型的数据结构定义,了解到Istio上只是定义的服务发现的接 ...
- 第十二章 Kubernetes的服务暴露插件--traefik
1.前言 之前部署的coredns实现了k8s的服务在集群内可以被自动发现,那么如何使得服务在k8s集群外被使用和访问呢? 使用nodeport星的Service:此方法只能使用iptables模型, ...
- Kubernetes之服务发现及负载Services
Service 概述 kubernetes 中的pod是有生生灭灭的,时刻都有可能被新的pod所代替,而不可复活(pod的生命周期).一旦一个pod生命终止,通过ReplicaSets动态创建和销毁p ...
- 5.kubernetes的服务暴露插件-Traefik
目录 1.部署traefik 2.准备资源配置清单 3.应用资源配置清单 4.检查创建资源 5.解析域名 6.配置反向代理 7.浏览器访问 部署traefik 在HDSS7-200.host.com上 ...
- K8S(04)核心插件-coredns服务
K8S核心插件-coredns服务 目录 K8S核心插件-coredns服务 1 coredns用途 1.1 为什么需要服务发现 2 coredns的部署 2.1 获取coredns的docker镜像 ...
- Prometheus在Kubernetes下的服务发现机制
Prometheus作为容器监控领域的事实标准,随着以Kubernetes为核心的云原生热潮的兴起,已经得到了广泛的应用部署.灵活的服务发现机制是Prometheus和Kubernetes两者得以连接 ...
- Docker与k8s的恩怨情仇(七)—— “服务发现”大法让你的内外交互原地起飞
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 第一章:Docker与k8s的恩怨情仇(一)-成为PaaS前浪的Cloud Foundry 第二章:Dock ...
- 基于 Consul 的 Docker Swarm 服务发现
Docker 是一种新型的虚拟化技术,它的目标在于实现轻量级操作系统的虚拟化.相比传统的虚拟化方案,Docker 虚拟化技术有一些很明显的优势:启动容器的速度明显快于传统虚拟化技术,同时创建一台虚拟机 ...
随机推荐
- C语言Printf()规定符号
%d 十进制有符号整数 %u 十进制无符号整数 %f 浮点数 %s 字符串 %c 单个字符 %p 指针的值 %e 指数形式的浮点数 %x, %X 无符号以十六进制表示的整数 %o 无符号以八进制表示的 ...
- SpringCloud(一)- SpringCloud简介
唯能极于情,故能极于剑 有问题或错误请及时联系小编或关注小编公众号 “CodeCow”,小编一定及时回复和改正,期待和大家一起学习交流 一.SpringCloud 1.1.Cloud 是什么 ?: 官 ...
- day18 迭代器
1,迭代器协议:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么就引起一个Stoplteration异常,只能往后走不能往前退: 2,可迭代对象:实现了迭代器协议的对象(如何实现: ...
- Lambda表达式用法大比较: Scala和Java 8
最近几年Lambda表达式风靡于编程界. 很多现代编程语言都把它作为函数式编程的基本组成部分. 基于JVM的编程语言如Scala,Groovy还有Clojure把它们作为关键部分集成在语言中.现在Ja ...
- 函数:exit()
函数名: exit() 所在头文件:stdlib.h(如果是"VC6.0"的话头文件为:windows.h) 功 能: 关闭所有文件,终止正在执行的进程. exit(1)表示异常退 ...
- html5学习之路_002
html块 html块元素 块元素在显示时,通常会以新行开始 如:<h1>.<p>.<ul> html内联元素 内联元素头通常不会以新行开始 如:<b> ...
- MvvmLight + Microsoft.Extensions.DependencyInjection + WpfApp(.NetCore3.1)
git clone MvvmLight失败,破网络, 就没有直接修改源码的方式来使用了 Nuget安装MvvmLightLibsStd10 使用GalaSoft.MvvmLight.Command命名 ...
- Java中的自动装箱拆箱
Java中的自动装箱拆箱 一.自动装箱与自动拆箱 自动装箱就是将基本数据类型转换为包装类类型,自动拆箱就是将包装类类型转换为基本数据类型. 1 // 自动装箱 2 Integer total = 90 ...
- Python之TestLink篇
如何让时间变慢? 你们不知道吧,这个时候翻开书,时间又变慢了一倍,可以这样延年益寿,哈哈哈 ------------------------------------------------------ ...
- Rocket - util - ECC
https://mp.weixin.qq.com/s/yato1PrnHe517J8twgZFOg 介绍ECC(Error Correcting Code/Error Checking and C ...