二进制部署k8s集群v1.23.9版本-13-安装CoreDns插件
13.1、CoreDns概述
简介:
- k8s的服务发现插件-CoreDns
- CoreDns其实就是将service的名字和cluster-ip做一个自动关联
部署k8s的内网资源配置清单http服务
在192.168.1.200运维主机上,配置一个nginx虚拟主机,用以提供k8s统一的资源配置清单访问入口
13.2、配置内网dns解析
vim /var/named/qgutech.com.zone
新增一条配置,注意序列号需要前滚
重启named服务
systemctl restart named
检测
dig -t A k8s-yaml.qgutech.com @192.168.1.197 +short
13.3、配置nginx
192.168.1.200服务器操作
cd /etc/nginx/conf.d/
mkdir /data/k8s-yaml
vim k8s-yaml.qgutech.com.conf
server {
listen 80;
server_name k8s-yaml.qgutech.com;
location / {
autoindex on;
default_type text/plain;
root /data/k8s-yaml;
}
}
cd /data/k8s-yaml
mkdir coredns
重启nginx
nginx -t
nginx -s reload
页面访问
http://k8s-yaml.qgutech.com
13.4、镜像配置
192.168.1.200服务器操作
cd /data/k8s-yaml/coredns
docker pull docker.io/coredns/coredns:1.9.0
docker images|grep coredns
打标签
docker tag 0857bcbd38c9 harbor.qgutech.com/public/coredns:v1.9.0
推送到harbor
docker push harbor.qgutech.com/public/coredns:v1.9.0
13.5、配置资源配置清单
vim cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
log
health
ready
kubernetes cluster.local 192.168.0.0/16
forward . 192.168.1.197
cache 30
loop
reload
loadbalance
}
vim dp.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: coredns
namespace: kube-system
labels:
k8s-app: coredns
kubernetes.io/name: "CoreDNS"
spec:
replicas: 1
selector:
matchLabels:
k8s-app: coredns
template:
metadata:
labels:
k8s-app: coredns
spec:
priorityClassName: system-cluster-critical
serviceAccountName: coredns
containers:
- name: coredns
image: harbor.qgutech.com/public/coredns:v1.9.0
args:
- -conf
- /etc/coredns/Corefile
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 9153
name: metrics
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
dnsPolicy: Default
volumes:
- name: config-volume
configMap:
name: coredns
items:
- key: Corefile
path: Corefile
vim 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
vim 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.4
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
- name: metrics
port: 9153
protocol: TCP
官方coredns资源配置清单下载地址
https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dns/coredns/coredns.yaml.base
13.6、应用资源配置清单
192.168.1.201服务器操作
kubectl apply -f http://k8s-yaml.qgutech.com/coredns/rbac.yaml
kubectl apply -f http://k8s-yaml.qgutech.com/coredns/cm.yaml
kubectl apply -f http://k8s-yaml.qgutech.com/coredns/dp.yaml
kubectl apply -f http://k8s-yaml.qgutech.com/coredns/svc.yaml
kubectl get all -n kube-system
dig -t A www.baidu.com @192.168.0.4 +short
dig -t A hfqg1-201.host.com @192.168.0.4 +short
验证
kubectl create deployment nginx-ds --image=harbor.qgutech.com/public/nginx:v1.21.5 -n kube-public
kubectl get pods -n kube-public
kubectl expose deployment nginx-ds --port=80 -n kube-public
kubectl get svc -n kube-public
dig -t A nginx-ds.kube-public.svc.cluster.local. @192.168.0.4 +short
至此,CoreDns安装完成,感谢观看!
本文来自博客园,作者:霸都运维,转载请注明原文链接:https://www.cnblogs.com/wangjie20200529/p/16613138.html