coredns.yaml文件如下所示

# __MACHINE_GENERATED_WARNING__

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
- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - get
---
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
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
  labels:
      addonmanager.kubernetes.io/mode: EnsureExists
data:
  Corefile: |
    .: {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
            pods insecure
            upstream
            fallthrough in-addr.arpa ip6.arpa
            ttl
        }
        prometheus :
        forward . /etc/resolv.conf
        cache
        loop
        reload
        loadbalance
    }
---
apiVersion: apps/v1
kind: Deployment
metadata:
  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:
  # . In order to make Addon Manager do not reconcile this replicas parameter.
  # . Default is .
  # . Will be tuned in real time if DNS horizontal auto-scaling is turned on.
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable:
  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:
        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:
          name: dns
          protocol: UDP
        - containerPort:
          name: dns-tcp
          protocol: TCP
        - containerPort:
          name: metrics
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /health
            port:
            scheme: HTTP
          initialDelaySeconds:
          timeoutSeconds:
          successThreshold:
          failureThreshold:
        readinessProbe:
          httpGet:
            path: /health
            port:
            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: v1
kind: Service
metadata:
  name: kube-dns
  namespace: kube-system
  annotations:
    prometheus.io/port: "
    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:
    protocol: UDP
  - name: dns-tcp
    port:
    protocol: TCP
  - name: metrics
    port:
    protocol: TCP

修改以上yaml文件中红色部分修改成自己对于的信息

kubectl apply -f coredns.yaml

执行apply  生成pod(需要替换镜像,不然会拉取失败)

[root@k8s-master yaml]# kubectl get all -n kube-system | grep coredns
pod/coredns-867ccfd476-9ghff              /     Running            42h
pod/coredns-867ccfd476-p5md4              /     Running            42h
deployment.apps/coredns                /                            44h
replicaset.apps/coredns-867ccfd476                                       44h
[root@k8s-master yaml]# 

创建测试的pod

[root@k8s-master test]# cat my-apache.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-apache
spec:
  replicas:
  template:
    metadata:
      labels:
        run: my-apache
    spec:
      containers:
      - name: my-apache
        image: httpd:2.4
        ports:
        - containerPort: 

---
apiVersion: v1
kind: Service
metadata:
  name: my-apache
  labels:
    run: my-apache
spec:
  type: NodePort
  ports:
  - port:
    targetPort:
    nodePort:
  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   AGE
my-apache-75f574f468-8psfw   /     Running             24h
my-apache-75f574f468-msrrn   /     Running             24h
[root@k8s-master test]# 

已经全部运行

[root@k8s-master test]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   /TCP        2d
my-apache    NodePort    :/TCP   24h
[root@k8s-master test]# curl 10.0.0.71
<html><body><h1>It works!</h1></body></html>
[root@k8s-master test]# 

由此可见dns服务是可用的

Kubernetes1.15 部署 coredns的更多相关文章

  1. kubespray2.11安装kubernetes1.15

    关于kubespray Kubespray是开源的kubernetes部署工具,整合了ansible,可以方便的部署高可用集群环境,官网地址:https://github.com/kubernetes ...

  2. consul实现kubernetes-1.15集群master的高可用访问实现

    1.准备consul环境,参考我之前的博客实现或参考consul的官网部署最新的consul. 2.本次测试使用的是kubernetes-1.15.0 3.初始化集群 1)准备初始化文件 contro ...

  3. Kubernetes 1.15部署日记-使用kubeadm--<7-8>

    7. 在k8s集群中run一个应用 nginx已经跑起来了到此kubernetes集群部署结束了. 8. 总结 此次部署kubernetes的起因是AI团队中的kubernetes项目跑在其他IP段网 ...

  4. 部署coredns

      1 前提:     1.1不依赖kubeadm的方式,适用于不是使用kubeadm创建的k8s集群,或者kubeadm初始化集群之后,删除了dns相关部署.      1.2 DNS IP :10 ...

  5. playbook部署coredns

    playbook部署coredns 说明test1是主控节点,目的是给test4 node节点安装coredns, 1.coredns-1.2.2.tar.gz安装包放到主控节点/server/sof ...

  6. 10、二进制安装K8s之部署CoreDNS 和Dashboard

    二进制安装K8s之部署CoreDNS 和Dashboard CoreDNS 和Dashboard 的yaml文件在 k8s源代码压缩包里面可以找到对应的配置文件,很多人从网上直接下载使用别人的,会导致 ...

  7. suse 12 二进制部署 Kubernetets 1.19.7 - 第11章 - 部署coredns组件

    文章目录 1.11.0.部署coredns 1.11.1.测试coredns功能 suse 12 二进制部署 Kubernetes 集群系列合集: suse 12 二进制部署 Kubernetets ...

  8. 使用kubeadm部署kubernetes1.9.1+coredns+kube-router(ipvs)高可用集群

    由于之前已经写了两篇部署kubernetes的文章,整个过程基本一致,所以这篇只着重说一下coredns和kube-router的部署. kube version: 1.9.1 docker vers ...

  9. 最新二进制安装部署kubernetes1.15.6集群---超详细教程

    00.组件版本和配置策略 00-01.组件版本 Kubernetes 1.15.6 Docker docker-ce-18.06.1.ce-3.el7 Etcd v3.3.13 Flanneld v0 ...

随机推荐

  1. Qt之使用setWindowFlags方法遇到的问题(追踪进入QWidget的源码分析原因,最后用WINAPI解决问题)good

    一.简述 前段时间在使用setWindowFlags方法时遇到了一个坑,具体情况是想通过窗口界面上一个checkBox来控制窗口当前状态是否置顶,而Qt提供了Qt::WindowStaysOnTopH ...

  2. 【Linux】Linux中常用操作命令(转)

    Linux简介及Ubuntu安装 Linux,免费开源,多用户多任务系统.基于Linux有多个版本的衍生.RedHat.Ubuntu.Debian 安装VMware或VirtualBox虚拟机.具体安 ...

  3. SQL Server修改标识列方法(备忘)

    原文:SQL Server修改标识列方法(备忘) SQL Server修改标识列方法 ----允许对系统表进行更新 exec sp_configure 'allow updates',1 reconf ...

  4. error C2760: 语法错误: 意外的令牌“标识符”,预期的令牌为“类型说明符”

    解决办法: 打开项目工程----> 属性 ---> c/c++ --> 语音 --> 符合模式 修改成否即可

  5. 微信小程序把玩(三十二)Image API

    原文:微信小程序把玩(三十二)Image API 选择图片时可设置图片是否是原图,图片来源.这用的也挺常见的,比如个人中心中设置头像,可以与wx.upLoadFile()API使用 主要方法: wx. ...

  6. Compile for Windows on Linux(交叉编译,在Linux下编译Windows程序),以OpenSSL为例

    OpenSSL for Windows In earlier articles, we have looked at how to create a gcc build environment on ...

  7. QTcpSocket类和QTcpServer类

    QTcpSocket 详细描述:QTcpSocket 类提供一个TCP套接字TCP是一个面向连接,可靠的的通信协议,非常适合于连续不断的数据传递QTcpSocket 是QAbstractSocket类 ...

  8. DELPHI之关于String的内存分配(引)

    在函数.过程或者方法中定义一个字符串变量时,由于我们知道在函数.过程或者方法中定义的变量为局部变量,它的内存 是在栈中分配的,但是这里有个小细节我们要注意,对于一个局部的字符串变量,它的大小为4字节, ...

  9. Ruby元编程:执行某个目录下的全部测试用例

    目前手里有个测试项目各个feature的测试用例都放在对应的子目录下,虽然有自动化测试框架的帮助执行起来很方便,但是偶尔也有需要在本地执行某个feature的全部测试用例集合.因为本人对shell脚本 ...

  10. TopFreeTheme精选免费模板【20130626】

    有一段时间没有发布的模板了,相信很多喜欢新模板的朋友有点焦急了!还好,今天我今天整理了13个最新的模板,主要是WordPress的,另外3个是关于Joomla的模板,他们分别是游戏主题.俱乐部主题以及 ...