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>

最新文章

  1. webpack解惑:require的五种用法
  2. 一次kibana小问题排查的过程记录
  3. 如何打开 系统信息窗体和 DirectX诊断工具
  4. 转义字符(\)对JavaScript中JSON.parse的影响概述
  5. # C/C++的笔试题目
  6. [应用][js+css3]3D盒子导航[PC端]
  7. Chrome Restful Api 测试工具 Postman-REST-Client离线安装包下载,Axure RP Extension for Chrome离线版下载
  8. 运行Python脚本的方法
  9. 【教程】手把手教你如何利用工具(IE9的F12)去分析模拟登陆网站(百度首页)的内部逻辑过程
  10. Task任务
  11. php5.6之后的版本使用curl以@+文件名的方式上传文件无效的解决版本
  12. js原生设计模式——2面向对象编程之继承—call(this)构造函数式继承
  13. XCode消除警告、错误
  14. final、finally、finalize
  15. springsecurity 源码解读之 SecurityContext
  16. Spring Boot, Java Config - No mapping found for HTTP request with URI [/…] in DispatcherServlet with name &#39;dispatcherServlet&#39;
  17. GDTR与LDTR
  18. oracle 9i/10gR2所有版本下载地址
  19. Haskell语言学习笔记(72)Free Monad
  20. Unity LuaFramework LuaBundleMode

热门文章

  1. springmvc-初次接触
  2. C++软件开发面试题总结
  3. Redis学习笔记(1)
  4. 12.Java连接Redis_Jedis_常用API
  5. Python数据分析:pandas玩转Excel (一)
  6. LM NTML NET-NTLM2理解及hash破解
  7. 七、Spring MVC高级技术
  8. 12 . Python3之网络编程
  9. cmd启动mysql,服务名无效
  10. CPU efficiency测量标准:DMIPS