Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build and use Coredns in kubernetes

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you how to build and use Coredns in kubernetes. I believe most people don't know how to install and use it. In order to let you learn, I summarized the following content. Without saying much, let's read on.

I. the function of Coredns

Key points: through coredns through service name, explain the corresponding cluter cluster IP2, Coredns installation (build services with containers) 1, set up a HTTP service on the operation and maintenance host to store yaml files ~] # cd / etc/nginx/conf.d/conf.d] # vi / etc/nginx/conf.d/k8s-yaml.od.com.confserver {listen 80; server_name k8smurf yaml.od.com; location / {autoindex on Default_type text/plain; root / data/k8s-yaml;}} conf.d] # mkdir / data/k8s-yamlconf.d] # nginx-tconf.d] # nginx-s reloadconf.d] # cd / data/k8s-yaml/k8s-yaml] # mkdir coredns

2. Create four yaml files Used to create coredns containers [root@test-operator coredns] # cat rbac.yaml apiVersion: v1kind: ServiceAccountmetadata: name: coredns namespace: kube-system labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: Reconcile name: system:corednsrules:- apiGroups:-"" Resources:-endpoints services-pods-namespaces verbs:-list-watch---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "true" labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: EnsureExists name: system:corednsroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:corednssubjects:- kind: ServiceAccount name: coredns namespace: kube-system- -[root@test-operator coredns] # cat cm.yamlapiVersion: v1kind: ConfigMapmetadata: name: coredns namespace: kube- Systemdata: Corefile: |.: 53 {errors log health ready kubernetes cluster.local 192.168.0.0 forward. 10.3.151.13 cache 30 loop reload loadbalance}- -[root@test-operator coredns] # cat dp.yamlapiVersion: apps/v1kind: Deploymentmetadata: 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: test-harbor.cedarhd.com/public/coredns:v1.6.1 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- -[root@test-operator coredns] # cat svc.yaml apiVersion: v1kind: Servicemetadata: name: coredns namespace: 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: 53 protocol: UDP-name: dns-tcp port: 53-name: metrics port: 9153 protocol: TCP3, Run coredns (installed successfully) on one of the node servers [root@test-nodes1 ~] # kubectl apply-f http://k8s-yaml.cedarhd.com/coredns/rbac.yamlserviceaccount/coredns createdclusterrole.rbac.authorization.k8s.io/system:coredns createdclusterrolebinding.rbac.authorization.k8s.io/system:coredns created [root@test-nodes1 ~] # kubectl apply-f http://k8s-yaml.cedarhd.com/coredns/cm.yamlconfigmap/coredns created [root@test-nodes1 ~] # Kubectl apply-f http://k8s-yaml.cedarhd.com/coredns/dp.yamldeployment.apps/coredns created [root@test-nodes1 ~] # kubectl apply-f http://k8s-yaml.cedarhd.com/coredns/svc.yamlservice/coredns created [root@test-nodes1 ~] # kubectl get all-n kube-systemNAME READY STATUS RESTARTS AGEpod/coredns-6c69fbcc6c-6vqgr 1Accord 1 Running 0 35sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEservice/coredns ClusterIP 192.168.0.2 53/UDP 53cm TCP 14sNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/coredns 9153Universe 1 1 1 36sNAME DESIRED CURRENT READY AGEreplicaset.apps/coredns-6c69fbcc6c 1 1 1 36s 3, usage scenario description

1. Create a new svc resource

[root@test-nodes1 ~] # kubectl create deployment nginx-test--image=test-harbor.cedarhd.com/public/nginx:v1.7.9deployment.apps/nginx-test created [root@test-nodes1 ~] # kubectl get all NAME READY STATUS RESTARTS AGEpod/nginx-test-5674474869-c4mzx 1 Running 0 5sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S ) AGEservice/kubernetes ClusterIP 192.168.0.1 443/TCP 8hNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/nginx-test 1 to 1 1 1 5sNAME DESIRED CURRENT READY AGEreplicaset.apps/nginx-test-5674474869 1 1 5s [root@test-nodes1 ~] # kubectl expose deployment nginx-test--port=80service/nginx-test exposed [root@test-nodes1 ~] # kubectl get allNAME READY STATUS RESTARTS AGEpod/nginx-test-5674474869-c4mzx 1 Running 0 42sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEservice/kubernetes ClusterIP 192.168.0.1 443/TCP 8hservice/nginx-test ClusterIP 192.168.109.13 80/TCP 8s # create the cluterip corresponding to svc as nginx-test and 192.168.109.13NAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/nginx-test 1 to 1 1 42sNAME DESIRED CURRENT READY AGEreplicaset.apps/nginx-test-5674474869 1 1 1 42s2 、 Enter one of the containers to view the interpretation effect [root@test-nodes2 ~] # kubectl get pods-n kube-publicNAME READY STATUS RESTARTS AGEnginx-ds-dk9hf 1 Running 0 3h53mnginx-ds-m6v9q 1 Running 0 3h53m [root@test-nodes2 ~] # kubectl exec-ti nginx-ds-dk9hf / bin/bash-n kube-publicPING nginx-test.default.svc.cluster.local (192 .168.109.13) 56 (84) bytes of data.64 bytes from nginx-test.default.svc.cluster.local (192.168.109.13): icmp_seq=1 ttl=64 time=0.070 ms64 bytes from nginx-test.default.svc.cluster.local (192.168.109.13): icmp_seq=2 ttl=64 time=0.077 ms#nginx-test.default defalut (the space where the container is located Must be added)

The above is the introduction of how to build and use Coredns in kubernetes. Is there anything to gain after reading it? If you want to know more about it, you are welcome to follow the industry information!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report