coredns.yaml文件如下所示
# __MACHINE_GENERATED_WARNING__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- apiGroups: - "" resources: - nodes verbs: - get---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---apiVersion: v1kind: ConfigMapmetadata: name: coredns namespace: kube-system labels: addonmanager.kubernetes.io/mode: EnsureExistsdata: Corefile: | .:53 { errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa ttl 30 } prometheus :9153 forward . /etc/resolv.conf cache 30 loop reload loadbalance }---apiVersion: apps/v1kind: Deploymentmetadata: name: coredns namespace: kube-system labels: k8s-app: kube-dns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "CoreDNS"spec: # replicas: not specified here: # 1. In order to make Addon Manager do not reconcile this replicas parameter. # 2. Default is 1. # 3. 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 annotations: seccomp.security.alpha.kubernetes.io/pod: 'docker/default' spec: priorityClassName: system-cluster-critical serviceAccountName: coredns tolerations: - key: "CriticalAddonsOnly" operator: "Exists" nodeSelector: beta.kubernetes.io/os: linux containers: - name: coredns image: k8s.gcr.io/coredns:1.3.1 imagePullPolicy: IfNotPresent resources: limits: memory: 70Mi 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 livenessProbe: httpGet: path: /health port: 8080 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 readinessProbe: httpGet: path: /health port: 8080 scheme: HTTP securityContext: allowPrivilegeEscalation: false capabilities: add: - NET_BIND_SERVICE drop: - all readOnlyRootFilesystem: true dnsPolicy: Default volumes: - name: config-volume configMap: name: coredns items: - key: Corefile path: Corefile---apiVersion: v1kind: Servicemetadata: 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" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "CoreDNS"spec: selector: k8s-app: kube-dns clusterIP: 10.0.0.2 ports: - name: dns port: 53 protocol: UDP - name: dns-tcp port: 53 protocol: TCP - name: metrics port: 9153 protocol: TCP
修改以上yaml文件中红色部分修改成自己对于的信息
kubectl apply -f coredns.yaml
执行apply 生成pod(需要替换镜像,不然会拉取失败)
[root@k8s-master yaml]# kubectl get all -n kube-system | grep corednspod/coredns-867ccfd476-9ghff 1/1 Running 13 42hpod/coredns-867ccfd476-p5md4 1/1 Running 15 42hdeployment.apps/coredns 2/2 2 2 44hreplicaset.apps/coredns-867ccfd476 2 2 2 44h[root@k8s-master yaml]#
创建测试的pod
[root@k8s-master test]# cat my-apache.yaml apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: my-apachespec: replicas: 2 template: metadata: labels: run: my-apache spec: containers: - name: my-apache image: httpd:2.4 ports: - containerPort: 80---apiVersion: v1kind: Servicemetadata: name: my-apache labels: run: my-apachespec: type: NodePort ports: - port: 80 targetPort: 80 nodePort: 30002 selector: run: my-apache
生成pod
[root@k8s-master test]# kubectl apply -f my-apache.yaml
查看pod运行状态
[root@k8s-master test]# kubectl get pod NAME READY STATUS RESTARTS AGEmy-apache-75f574f468-8psfw 1/1 Running 1 24hmy-apache-75f574f468-msrrn 1/1 Running 0 24h[root@k8s-master test]#
已经全部运行
[root@k8s-master test]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.0.0.1443/TCP 2dmy-apache NodePort 10.0.0.71 80:30002/TCP 24h[root@k8s-master test]# curl 10.0.0.71 It works!
[root@k8s-master test]#
由此可见dns服务是可用的