playbook部署coredns

playbook部署coredns

说明test1是主控节点,目的是给test4 node节点安装coredns,

1、coredns-1.2.2.tar.gz安装包放到主控节点/server/software/k8s/目录下,由playbook中的docker导入镜像

2、准备hosts文件

cat >/k8s/profile/hosts <<EOF
[k8s]
192.168.0.91
192.168.0.92
192.168.0.93

[test0]
192.168.0.92
192.168.0.93

[test1]
192.168.0.91

[test2]
192.168.0.92

[test3]
192.168.0.93

[test4]
192.168.0.94
EOF

3、准备playbook文件

cat >/k8s/profile/deploy_coredns.yaml <<EOF
- hosts: test4
  remote_user: root
  become: yes
  become_method: sudo
  vars:
    cluster_dns_svc_ip: 10.254.0.2
    iface: ens33
  tasks:
    - name: copy coredns config file
      template: src=/k8s/profile/coredns.yaml.j2 dest=/k8s/profile/coredns.yaml
    - name: mkdir directory for coredns package
      file: dest=/server/software/k8s/ state=directory mode=0755
    - name: copy coredns-1.2.2.tar
      copy: src=/server/software/k8s/coredns-1.2.2.tar.gz dest=/server/software/k8s/
    - name: load coredns-1.2.2.tar.gz to docker
      shell: docker load < /server/software/k8s/coredns-1.2.2.tar.gz
    - name: install_coredns
      command: kubectl apply -f /k8s/profile/coredns.yaml
EOF

4、准备coredns模板文件

cat >/k8s/profile/coredns.yaml.j2 <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: coredns
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: system:coredns
rules:
- apiGroups:
  - ""
  resources:
  - endpoints
  - services
  - pods
  - namespaces
  verbs:
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1beta1
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
        kubernetes cluster.local. in-addr.arpa ip6.arpa {
          pods insecure
          upstream
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
        reload
        loadbalance
    }
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: coredns
  namespace: kube-system
  labels:
    k8s-app: kube-dns
    kubernetes.io/name: "CoreDNS"
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  selector:
    matchLabels:
      k8s-app: kube-dns
  template:
    metadata:
      labels:
        k8s-app: kube-dns
    spec:
      serviceAccountName: coredns
      tolerations:
        - key: node-role.kubernetes.io/master
          effect: NoSchedule
        - key: "CriticalAddonsOnly"
          operator: "Exists"
      containers:
      - name: coredns
        image: coredns/coredns:1.2.0
        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
      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: cluster_dns_svc_ip
  ports:
  - name: dns
    port: 53
    protocol: UDP
  - name: dns-tcp
    port: 53
    protocol: TCP
EOF

5、开始部署

[[email protected] profile]# ansible-playbook /k8s/profile/deploy_coredns.yaml 

原文地址:https://www.cnblogs.com/effortsing/p/10356902.html

时间: 2024-11-10 13:01:31

playbook部署coredns的相关文章

部署coredns

1 前提: 1.1不依赖kubeadm的方式,适用于不是使用kubeadm创建的k8s集群,或者kubeadm初始化集群之后,删除了dns相关部署. 1.2 DNS IP :10.96.0.10 2 部署coredns 2.1 下载包 mkdir coredns && cd coredns wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/coredns.yaml.sed wget htt

(七)部署coredns组件

#(1)coredns简介 coredns服务监视kubernetes api , 为每一个service创建dns记录用于域名解析;这样访问pod资源资源只需要访问service名即可,而不需要关系pod容器的ip地址的变化; #(2)部署coredns cd /temp/k8s/coredns wget https://gitee.com/love-docker/docker/raw/master/k8s1.9.6/coredns/coredns.yaml kubectl apply -f

通过PlayBook部署Zabbix(6)

title: 通过PlayBook部署Zabbix(6) date: 2018-12-03 19:33:24 tags: Ansible categories: Ansible copyright: true --- Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能,ansible是基于模块工作的,本身没有批量部署的能力,真正具有批量部署

通过Playbook部署LAMP(5)

title: 通过Playbook部署LAMP(5) date: 2018-12-03 13:24:07 tags: Ansible categories: Ansible copyright: true --- Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具 (puppet.cfengine.chef.func.fabric) 的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能,Ansible是基于模块工作的,本身没有批量部署的能力,真正具有批量部署

09-1.部署 coredns 插件

09-1.部署 coredns 插件 修改配置文件 将下载的 kubernetes-server-linux-amd64.tar.gz 解压后,再解压其中的 kubernetes-src.tar.gz 文件. coredns 对应的目录是:cluster/addons/dns. $ pwd /opt/k8s/kubernetes/cluster/addons/dns $ cp coredns.yaml.base coredns.yaml $ diff coredns.yaml.base core

部署CoreDNS v1.6.6

coredns镜像版本:v1.6.6以下是部署所需YAML 文件, 主要修改位置:Service中的clusterIPYAML文件来源:https://github.com/coredns/deployment/tree/master/kubernetes coredns.yaml.sed 修改而来. apiVersion: v1 kind: ServiceAccount metadata: name: coredns namespace: kube-system --- apiVersion:

kubernetes二进制部署coredns(12)

CoreDNS是一个Go语言实现的链式插件DNS服务端,是CNCF成员,是一个高性能.易扩展的DNS服务端.可以很方便的部署在k8s集群中,用来代替kube-dns 具体的区别可以参考官方文档或者:https://zhuanlan.zhihu.com/p/80141656?from_voters_page=true 原理:kubedns: kubedns 基于 SkyDNS 库,通过 apiserver 监听 Service 和 Endpoints 的变更事件同时也同步到本地 Cache,实现了

playbook部署mangodb

playbook文件 [[email protected] ~]# cat deploy_mongo.yaml --- - hosts: webservers become: yes become_method: sudo vars: mongodb_datadir_prefix: /data mongod_port: 25000 tasks: - name: create the mongodb user user: name=mongodb comment="MongoDB" -

CoreDNS for kubernetes Service Discovery

一.CoreDNS简介 Kubernetes包括用于服务发现的DNS服务器Kube-DNS. 该DNS服务器利用SkyDNS的库来为Kubernetes pod和服务提供DNS请求.SkyDNS2的作者,Miek Gieben,创建了一个新的DNS服务器,CoreDNS,它采用更模块化,可扩展的框架构建. Infoblox已经与Miek合作,将此DNS服务器作为Kube-DNS的替代品. CoreDNS利用作为Web服务器Caddy的一部分而开发的服务器框架.该框架具有非常灵活,可扩展的模型,用