This commit is contained in:
HuaYu 2023-09-27 22:40:01 +08:00
parent b19fecd173
commit 27358f3a8a
5 changed files with 276 additions and 0 deletions

208
dns/CoreDNS.md Normal file
View File

@ -0,0 +1,208 @@
## 配置
```shell
cat > coredns.yaml << "EOF"
apiVersion: v1
kind: ServiceAccount
metadata:
name: coredns
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:coredns
rules:
- apiGroups:
- ""
resources:
- endpoints
- services
- pods
- namespaces
verbs:
- list
- watch
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
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
name: system:coredns
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:coredns
subjects:
- kind: ServiceAccount
name: coredns
namespace: kube-system
---
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . /etc/resolv.conf {
max_concurrent 1000
}
cache 30
loop
reload
loadbalance
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: coredns
namespace: kube-system
labels:
k8s-app: kube-dns
kubernetes.io/name: "CoreDNS"
spec:
# replicas: not specified here:
# 1. Default is 1.
# 2. Will be tuned in real time if DNS horizontal auto-scaling is turned on.
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
selector:
matchLabels:
k8s-app: kube-dns
template:
metadata:
labels:
k8s-app: kube-dns
spec:
priorityClassName: system-cluster-critical
serviceAccountName: coredns
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
nodeSelector:
kubernetes.io/os: linux
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: k8s-app
operator: In
values: ["kube-dns"]
topologyKey: kubernetes.io/hostname
containers:
- name: coredns
image: coredns/coredns:1.8.4
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 170Mi
requests:
cpu: 100m
memory: 70Mi
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
readOnly: true
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 9153
name: metrics
protocol: TCP
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_BIND_SERVICE
drop:
- all
readOnlyRootFilesystem: true
livenessProbe:
httpGet:
path: /health
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /ready
port: 8181
scheme: HTTP
dnsPolicy: Default
volumes:
- name: config-volume
configMap:
name: coredns
items:
- key: Corefile
path: Corefile
---
apiVersion: v1
kind: Service
metadata:
name: kube-dns
namespace: kube-system
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "CoreDNS"
spec:
selector:
k8s-app: kube-dns
clusterIP: 10.96.0.2
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
protocol: TCP
- name: metrics
port: 9153
protocol: TCP
EOF
```
## 启动
```shell
kubectl apply -f coredns.yaml
```

42
dns/CoreDNS绑定bind.md Normal file
View File

@ -0,0 +1,42 @@
```sh
# 查看所在pod
[root@hy-node3 ~]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-7cc8dd57d9-jhvnj 1/1 Running 4 7d21h
calico-node-lm24q 1/1 Running 9 20d
calico-node-p2pn4 1/1 Running 5 20d
coredns-675db8b7cc-s6z7g 1/1 Running 1 7d21h
snapshot-controller-0 1/1 Running 0 7d6h
# 找到对应service,使用serviceip
[root@hy-node3 ~]# kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-controller-manager-svc ClusterIP None <none> 10257/TCP 13d
kube-dns ClusterIP 10.96.0.2 <none> 53/UDP,53/TCP,9153/TCP 20d
kube-scheduler-svc ClusterIP None <none> 10259/TCP 13d
kubelet ClusterIP None <none> 10250/TCP,10255/TCP,4194/TCP 13d
# 找个ip查看dns是否能够解析
[root@hy-node3 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21d
nginx-service-nodeport NodePort 10.96.231.91 <none> 80:30001/TCP 20d
# 解析测试
dig -t a www.baidu.com @10.96.0.2
[root@hy-node3 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.120
nameserver 223.6.6.6
nameserver 223.5.5.5
# 编辑coredns配置文件
kubectl edit configmap coredns -n kube-system
```
![修改core-dns配置文件](img/QQ截图20230927214654.png)
```sh
# 查看是否可以滚动升级
[root@hy-node3 ~]# kubectl get deployment.apps -n kube-system
NAME READY UP-TO-DATE AVAILABLE AGE
calico-kube-controllers 1/1 1 1 20d
coredns 1/1 1 1 20d
[root@hy-node3 ~]# kubectl rollout restart deployment coredns -n kube-system
deployment.apps/coredns restarted
```

25
dns/bind.md Normal file
View File

@ -0,0 +1,25 @@
```sh
yum -y install bind
vi /etc/named.conf
vi /etc/named.rfc1912.zones
cd /var/named/
ll
cp -p named.localhost hy.com
cp -p named.localhost hy.com.zone
ll
rm hy.com
ll
vivi
vi hy.com.zone
systemctl enbled named
systemctl enable named
systemctl restart named
systemctl start named
systemctl status named.service
vi hy.com.zone
vi /etc/named.rfc1912.zones
vi hy.com.zone
systemctl start named
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -1,3 +1,4 @@
kubectl explain service.spec.ports
nodeport nodeport
clusterid clusterid
headlss headlss