diff --git a/dns/CoreDNS.md b/dns/CoreDNS.md new file mode 100644 index 0000000..3114a71 --- /dev/null +++ b/dns/CoreDNS.md @@ -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 +``` diff --git a/dns/CoreDNS绑定bind.md b/dns/CoreDNS绑定bind.md new file mode 100644 index 0000000..9d47236 --- /dev/null +++ b/dns/CoreDNS绑定bind.md @@ -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 10257/TCP 13d +kube-dns ClusterIP 10.96.0.2 53/UDP,53/TCP,9153/TCP 20d +kube-scheduler-svc ClusterIP None 10259/TCP 13d +kubelet ClusterIP 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 443/TCP 21d +nginx-service-nodeport NodePort 10.96.231.91 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 +``` \ No newline at end of file diff --git a/dns/bind.md b/dns/bind.md new file mode 100644 index 0000000..818309b --- /dev/null +++ b/dns/bind.md @@ -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 + +``` \ No newline at end of file diff --git a/dns/img/QQ截图20230927214654.png b/dns/img/QQ截图20230927214654.png new file mode 100644 index 0000000..4fa360d Binary files /dev/null and b/dns/img/QQ截图20230927214654.png differ diff --git a/k8s/port.md b/k8s/port.md index 4ffbd9f..01f1c41 100644 --- a/k8s/port.md +++ b/k8s/port.md @@ -1,3 +1,4 @@ +kubectl explain service.spec.ports nodeport clusterid headlss