├── .gitignore
├── group_vars
├── master.yml
├── node.yml
├── etcd.yml
└── all.yml
├── vars
├── prod.yml
└── dev.yml
├── files
├── calico-v3.24.1.images.tar.gz
├── infra-pause.3.7.image.tar.gz
├── flannel-v0.26.2.images.tar.gz
├── kubeadm-v1.24.0.images.tar.gz
├── kube-calico.yml
└── kube-flannel.yml
├── roles
├── etcd
│ ├── tasks
│ │ ├── main.yml
│ │ ├── service.yml
│ │ └── cert.yml
│ ├── files
│ │ ├── client-csr.json
│ │ ├── ca-csr.json
│ │ ├── etcd-env.service
│ │ ├── etcd-conf.service
│ │ └── ca-config.json
│ ├── handlers
│ │ └── main.yml
│ └── templates
│ │ ├── etcd-cluster-csr.j2
│ │ ├── etcd-env.j2
│ │ ├── etcd-service.j2
│ │ └── etcd-conf.j2
├── kube-node
│ ├── tasks
│ │ ├── main.yml
│ │ ├── config.yml
│ │ └── join.yml
│ └── templates
│ │ └── kubeadm-v1.24.0.j2
├── common
│ ├── files
│ │ ├── ipvs.modules
│ │ ├── set-cgroupv2.sh
│ │ ├── set-nice.sh
│ │ ├── set-conntrack.sh
│ │ ├── syslog
│ │ ├── rc.local
│ │ ├── dev-sudoers
│ │ ├── clean-kubelet-log.sh
│ │ └── sysctl.conf
│ ├── tasks
│ │ ├── image.yml
│ │ ├── main.yml
│ │ ├── kube.yml
│ │ ├── sa.yml
│ │ ├── prepare.yml
│ │ └── container-runtime.yml
│ └── templates
│ │ ├── docker-daemon.j2
│ │ └── containerd.toml.j2
├── kube-network
│ └── tasks
│ │ ├── main.yml
│ │ ├── calico.yml
│ │ └── flannel.yml
└── kube-master
│ ├── tasks
│ ├── main.yml
│ ├── check.yml
│ ├── set-lb.yml
│ ├── image.yml
│ └── init.yml
│ ├── files
│ └── apiserver-audit-policy.yml
│ └── templates
│ └── kubeadm-v1.24.0.j2
├── hosts
└── demo
├── etcd-create.yml
├── cluster-expand.yml
├── cluster-create.yml
├── cluster-destroy.yml
├── cluster-reduce.yml
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/group_vars/master.yml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/group_vars/node.yml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/group_vars/etcd.yml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/vars/prod.yml:
--------------------------------------------------------------------------------
1 | env: prod
2 |
--------------------------------------------------------------------------------
/files/calico-v3.24.1.images.tar.gz:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/files/infra-pause.3.7.image.tar.gz:
--------------------------------------------------------------------------------
1 | pause镜像
--------------------------------------------------------------------------------
/files/flannel-v0.26.2.images.tar.gz:
--------------------------------------------------------------------------------
1 | kubeadm images tar包
--------------------------------------------------------------------------------
/files/kubeadm-v1.24.0.images.tar.gz:
--------------------------------------------------------------------------------
1 | kubeadm images tar包
--------------------------------------------------------------------------------
/roles/etcd/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - import_tasks: cert.yml
2 |
3 | - import_tasks: service.yml
--------------------------------------------------------------------------------
/roles/kube-node/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - import_tasks: join.yml
2 |
3 | - import_tasks: config.yml
--------------------------------------------------------------------------------
/files/kube-calico.yml:
--------------------------------------------------------------------------------
1 | calico安装yml
2 | wget https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/calico.yaml
--------------------------------------------------------------------------------
/files/kube-flannel.yml:
--------------------------------------------------------------------------------
1 | flannel安装yml
2 | wget https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
--------------------------------------------------------------------------------
/roles/etcd/files/client-csr.json:
--------------------------------------------------------------------------------
1 | {
2 | "CN": "etcd-client",
3 | "key": {
4 | "algo": "ecdsa",
5 | "size": 256
6 | }
7 | }
--------------------------------------------------------------------------------
/roles/etcd/handlers/main.yml:
--------------------------------------------------------------------------------
1 | - name: Restart etcd service
2 | systemd:
3 | name: etcd
4 | state: restarted
5 | enabled: yes
6 | daemon_reload: yes
7 |
--------------------------------------------------------------------------------
/roles/common/files/ipvs.modules:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | modprobe -- ip_vs
3 | modprobe -- ip_vs_rr
4 | modprobe -- ip_vs_wrr
5 | modprobe -- ip_vs_sh
6 | modprobe -- nf_conntrack
--------------------------------------------------------------------------------
/roles/common/tasks/image.yml:
--------------------------------------------------------------------------------
1 | - name: Copy infra pause images
2 | copy:
3 | src: files/{{ item }}
4 | dest: /tmp/
5 | with_items:
6 | - infra-pause.3.7.image.tar.gz
7 |
--------------------------------------------------------------------------------
/roles/common/tasks/main.yml:
--------------------------------------------------------------------------------
1 | # k8s host prepare
2 | - import_tasks: prepare.yml
3 |
4 | # k8s rpm install
5 | - import_tasks: kube.yml
6 |
7 | # sre additional configs
8 | - import_tasks: sa.yml
9 |
--------------------------------------------------------------------------------
/roles/etcd/files/ca-csr.json:
--------------------------------------------------------------------------------
1 | {
2 | "CN": "etcd",
3 | "key": {
4 | "algo": "rsa",
5 | "size": 2048
6 | },
7 | "ca": {
8 | "expiry": "876000h"
9 | }
10 | }
--------------------------------------------------------------------------------
/roles/common/files/set-cgroupv2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ ! -d "/var/kernel/cgroup2" ]; then
4 | mkdir -p /var/kernel/cgroup2
5 | fi
6 | mountpoint -q /var/kernel/cgroup2 || mount -t cgroup2 nodev /var/kernel/cgroup2
7 |
--------------------------------------------------------------------------------
/roles/kube-network/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - import_tasks: flannel.yml
2 | tags: flannel
3 | when: cluster_network_type == "flannel"
4 |
5 | - import_tasks: calico.yml
6 | tags: calico
7 | when: cluster_network_type == "calico"
--------------------------------------------------------------------------------
/roles/common/files/set-nice.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -eu
4 |
5 | nice_value="-20"
6 |
7 | for pid in $(pgrep -u root '^ksoftirqd/[0-9]+$'); do
8 | chrt -o -p 0 "$pid"
9 | renice -n "$nice_value" -p "$pid"
10 | done
11 |
--------------------------------------------------------------------------------
/hosts/demo:
--------------------------------------------------------------------------------
1 | ; all: centos 4.19
2 | [master]
3 | k8s-master-[1:3]
4 |
5 | [etcd]
6 | k8s-etcd-[1:5]
7 |
8 | [node]
9 | k8s-node-[1:100]
10 |
11 |
12 | [all:vars]
13 | ; k = v
14 |
15 | [master:vars]
16 | ; k = v
17 |
18 | [etcd:vars]
19 | ; k = v
20 |
--------------------------------------------------------------------------------
/roles/kube-master/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - import_tasks: image.yml
2 | tags: kubeadm-images
3 |
4 | - import_tasks: init.yml
5 | tags: init-master
6 |
7 | - import_tasks: check.yml
8 | tags: check-master
9 |
10 | # - import_tasks: set-lb.yml
11 | # tags: set-cm-lb
--------------------------------------------------------------------------------
/roles/common/files/set-conntrack.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # note: https://www.cnblogs.com/jianyungsun/p/12554455.html
3 | set -eu
4 |
5 | modprobe nf_conntrack
6 | sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=10
7 | sysctl -w net.netfilter.nf_conntrack_tcp_timeout_fin_wait=10
8 |
--------------------------------------------------------------------------------
/roles/etcd/files/etcd-env.service:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=etcd
3 | After=network.target
4 |
5 | [Service]
6 | Type=notify
7 | LimitNOFILE=655350
8 | EnvironmentFile=/etc/etcd/etcd.env
9 | ExecStart=/usr/local/bin/etcd
10 |
11 | Restart=always
12 | StartLimitInterval=0
13 | RestartSec=10
14 |
15 | [Install]
16 | WantedBy=multi-user.target
--------------------------------------------------------------------------------
/roles/common/files/syslog:
--------------------------------------------------------------------------------
1 | /var/log/cron
2 | /var/log/maillog
3 | /var/log/messages
4 | /var/log/secure
5 | /var/log/spooler
6 | {
7 | missingok
8 | sharedscripts
9 | dateext
10 | rotate 25
11 | size 40M
12 | compress
13 | dateformat -%Y%m%d%s
14 | postrotate
15 | /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
16 | endscript
17 | }
18 |
--------------------------------------------------------------------------------
/etcd-create.yml:
--------------------------------------------------------------------------------
1 | - name: Common tasks for all
2 | hosts: all
3 | become: yes
4 | gather_facts: yes
5 | any_errors_fatal: yes
6 | # ignore_errors: yes
7 | vars_files:
8 | - vars/{{ env }}.yml
9 | roles:
10 | - { role: common, tags: common }
11 |
12 | - name: Build etcd cluster
13 | hosts: etcd
14 | become: yes
15 | gather_facts: no
16 | any_errors_fatal: yes
17 | vars_files:
18 | - vars/{{ env }}.yml
19 | roles:
20 | - { role: etcd, tags: etcd }
--------------------------------------------------------------------------------
/roles/common/tasks/kube.yml:
--------------------------------------------------------------------------------
1 |
2 | - import_tasks: image.yml
3 |
4 | - import_tasks: container-runtime.yml
5 |
6 | - name: Install kubelet/kubectl/kubeadm
7 | yum:
8 | name: "{{ kube_packages[k8s_version] }}"
9 | state: present
10 | disable_plugin: fastestmirror
11 | update_cache: yes
12 | when: 1==2 # 直接跳过, 测试机器已安装
13 |
14 | - name: Set cluster name
15 | copy:
16 | dest: /root/.kube/cluster
17 | content: |
18 | {"cluster_name":"{{ cluster_name }}"}
19 |
--------------------------------------------------------------------------------
/cluster-expand.yml:
--------------------------------------------------------------------------------
1 | - name: Common tasks for all
2 | hosts: node
3 | become: yes
4 | gather_facts: yes
5 | any_errors_fatal: yes
6 | # ignore_errors: yes
7 | vars_files:
8 | - vars/{{ env }}.yml
9 | roles:
10 | - { role: common, tags: common }
11 |
12 | - name: Deploy k8s node
13 | hosts: node
14 | become: yes
15 | gather_facts: yes
16 | any_errors_fatal: yes
17 | vars_files:
18 | - vars/{{ env }}.yml
19 | roles:
20 | - { role: kube-node, tags: kube-node }
--------------------------------------------------------------------------------
/roles/kube-master/tasks/check.yml:
--------------------------------------------------------------------------------
1 | - name: Check master node
2 | shell: kubectl get node `hostname`
3 | register: get_master_result
4 | until: get_master_result is succeeded
5 | retries: 5
6 | delay: 2
7 |
8 | - name: Check kube-system pod
9 | shell: kubectl -n kube-system get pods -l tier=control-plane |grep Running|wc -l
10 | register: control_plane_pods_status_result
11 | until: control_plane_pods_status_result.stdout | int == master_count * 3
12 | retries: 3
13 | delay: 3
14 | run_once: true
--------------------------------------------------------------------------------
/roles/etcd/files/etcd-conf.service:
--------------------------------------------------------------------------------
1 | # /usr/lib/systemd/system/etcd.service
2 | [Unit]
3 | Description=etcd key-value store
4 | Documentation=https://github.com/etcd-io/etcd
5 | Wants=network-online.target
6 | After=network-online.target
7 |
8 | [Service]
9 | Type=notify
10 | ExecStart=/usr/local/bin/etcd --config-file=/etc/etcd/etcd.conf.yml
11 | ExecReload=/bin/kill -HUP $MAINPID
12 | Restart=on-failure
13 | KillSignal=SIGTERM
14 | # User=etcd
15 | RestartSec=20
16 | SyslogIdentifier=etcd
17 |
18 | LimitNOFILE=65535
19 | LimitNPROC=65535
20 | LimitCORE=infinity
21 |
22 | [Install]
23 | WantedBy=multi-user.target
--------------------------------------------------------------------------------
/roles/common/files/rc.local:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
3 | #
4 | # It is highly advisable to create own systemd services or udev rules
5 | # to run scripts during boot instead of using this file.
6 | #
7 | # In contrast to previous versions due to parallel execution during boot
8 | # this script will NOT be run after all other services.
9 | #
10 | # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
11 | # that this script will be executed during boot.
12 |
13 | touch /var/lock/subsys/local
14 |
15 | #rc.sre script
16 | for i in $(ls /etc/rc.d/rc.sre/); do
17 | sh /etc/rc.d/rc.sre/$i
18 | done
19 |
--------------------------------------------------------------------------------
/roles/etcd/templates/etcd-cluster-csr.j2:
--------------------------------------------------------------------------------
1 | {
2 | "CN": "{{ ansible_facts.hostname }}",
3 | "hosts": [
4 | {% for host in groups.etcd %}
5 | "{{ hostvars[host].ansible_facts.hostname }}",
6 | {% endfor %}
7 | {% for host in groups.etcd %}
8 | "{{ hostvars[host].ansible_facts.nodename }}",
9 | {% endfor %}
10 | {% for host in groups.etcd %}
11 | "{{ hostvars[host].ansible_facts.default_ipv4.address }}",
12 | {% endfor %}
13 | "127.0.0.1",
14 | "0.0.0.0"
15 | ],
16 | "key": {
17 | "algo": "ecdsa",
18 | "size": 256
19 | },
20 | "names": [
21 | {
22 | "C": "CN",
23 | "L": "SH",
24 | "ST": "SH"
25 | }
26 | ]
27 | }
28 |
--------------------------------------------------------------------------------
/roles/common/files/dev-sudoers:
--------------------------------------------------------------------------------
1 | dev ALL=(ALL) NOPASSWD:/usr/bin/journalctl,/usr/sbin/tcpdump,/usr/sbin/iptables,/usr/bin/du,/usr/sbin/iotop,/usr/bin/find,/usr/bin/perf,/bin/ls,/home/dev/pod-ip-release,/usr/local/bin/etcd,/usr/local/bin/etcdctl,/bin/netstat,/bin/docker,/bin/zcat
2 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /var/log/message*
3 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /etc/kubernetes/kubelet.conf
4 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /etc/kubernetes/manifests/kube*
5 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /data0/log*
6 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /var/lib/kubelet/cpu_manager_state
7 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /var/lib/kubelet/config.yaml
8 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /var/lib/kubelet/kubeadm-flags.env
9 | dev ALL=(ALL) NOPASSWD:/usr/bin/cat /var/lib/pke*
10 |
--------------------------------------------------------------------------------
/group_vars/all.yml:
--------------------------------------------------------------------------------
1 | kernel_version: 4.19.95-35
2 |
3 | cluster_name: dev-k8s
4 | cluster_lb: 1.1.1.1
5 | cluster_lb_port: 8888
6 | cluster_network_type: flannel
7 |
8 | system_reserved_cpu: 500m
9 | system_reserved_memory: 200m
10 |
11 | k8s_version: v1.24.0
12 | kube_packages:
13 | "v1.24.0":
14 | - kubelet-1.24.0-0
15 | - kubectl-1.24.0-0
16 | - kubeadm-1.24.0-0
17 |
18 | # 已经提前通过ansible安装, 不写入playbook
19 | kube_rpm_packages:
20 | "v1.24.0":
21 | - kubelet-1.24.0-0.x86_64.rpm
22 | - kubectl-1.24.0-0.x86_64.rpm
23 | - kubeadm-1.24.0-0.x86_64.rpm
24 | - kubernetes-cni-1.2.0-0.x86_64.rpm
25 | - cri-tools-1.19.0-0.x86_64.rpm
26 |
27 | container_runtime: containerd # docker
28 | docker_version: docker-ce-20.10.10-3.el7
29 | containerd_version: 1.4.12-3.1.el7
30 |
--------------------------------------------------------------------------------
/roles/kube-network/tasks/calico.yml:
--------------------------------------------------------------------------------
1 | - name: Copy calico images
2 | copy:
3 | src: files/{{ item }}
4 | dest: /tmp/
5 | with_items:
6 | - calico-v3.24.1.images.tar.gz
7 |
8 | - name: Load calico images
9 | shell: docker load -i /tmp/calico-v3.24.1.images.tar.gz
10 | when: container_runtime == "docker"
11 |
12 | - name: Load calico images
13 | shell: ctr -n k8s.io images import /tmp/calico-v3.24.1.images.tar.gz
14 | when: container_runtime == "containerd"
15 |
16 | - name: Install calico network
17 | block:
18 | - name: Copy calico.yml to master
19 | copy:
20 | src: files/kube-calico.yml
21 | dest: /tmp/kube-calico.yml
22 | - name: Apply calico.yml
23 | shell: kubectl apply -f /tmp/kube-calico.yml
24 | when: inventory_hostname == groups.master|first
--------------------------------------------------------------------------------
/roles/kube-network/tasks/flannel.yml:
--------------------------------------------------------------------------------
1 | - name: Copy flannel images
2 | copy:
3 | src: files/{{ item }}
4 | dest: /tmp/
5 | with_items:
6 | - flannel-v0.26.2.images.tar.gz
7 |
8 | - name: Load flannel images
9 | shell: docker load -i /tmp/flannel-v0.26.2.images.tar.gz
10 | when: container_runtime == "docker"
11 |
12 | - name: Load flannel images
13 | shell: ctr -n k8s.io images import /tmp/flannel-v0.26.2.images.tar.gz
14 | when: container_runtime == "containerd"
15 |
16 | - name: Install flannel network
17 | block:
18 | - name: Copy flannel.yml to master
19 | copy:
20 | src: files/kube-flannel.yml
21 | dest: /tmp/kube-flannel.yml
22 | - name: Apply flannel.yml
23 | shell: kubectl apply -f /tmp/kube-flannel.yml
24 | when: inventory_hostname == groups.master|first
--------------------------------------------------------------------------------
/roles/common/templates/docker-daemon.j2:
--------------------------------------------------------------------------------
1 | {
2 | {% if gpu %}
3 | "default-runtime": "nvidia",
4 | "runtimes": {
5 | "nvidia": {
6 | "path": "/usr/bin/nvidia-container-runtime",
7 | "runtimeArgs": []
8 | }
9 | },
10 | {% endif %}
11 | "log-driver": "json-file",
12 | "log-opts": {
13 | "max-size": "200m",
14 | "max-file": "{{ docker_log_opts_max_file }}"
15 | },
16 | "exec-opts": [
17 | "native.cgroupdriver=systemd"
18 | ],
19 | "live-restore": true,
20 | "storage-driver": "overlay2",
21 | {% if docker_storage_opts is defined %}
22 | "storage-opts": {{ docker_storage_opts | to_json }},
23 | {% endif %}
24 | "graph": "/data0/docker"
25 | {%- if insecure_registries %},
26 | "insecure-registries": {{ insecure_registries | to_json }}
27 | {% endif %}
28 | }
29 |
--------------------------------------------------------------------------------
/roles/kube-node/templates/kubeadm-v1.24.0.j2:
--------------------------------------------------------------------------------
1 | apiVersion: kubeadm.k8s.io/v1beta3
2 | kind: JoinConfiguration
3 | caCertPath: /etc/kubernetes/pki/ca.crt
4 | discovery:
5 | bootstrapToken:
6 | # apiServerEndpoint: {{ cluster_lb }}:{{ cluster_lb_port }}
7 | apiServerEndpoint: {{ hostvars[groups.master | first].ansible_facts.default_ipv4.address }}:6443
8 | token: {{ kubeadm_token }}
9 | unsafeSkipCAVerification: true
10 | timeout: 5m0s
11 | tlsBootstrapToken: {{ kubeadm_token }}
12 | nodeRegistration:
13 | criSocket: unix:///var/run/containerd/containerd.sock
14 | imagePullPolicy: IfNotPresent
15 | taints:
16 | - effect: NoSchedule
17 | key: node-role.kubernetes.io/node
18 | kubeletExtraArgs:
19 | cpu-manager-policy: "static"
20 | log-dir: /data0/log/kube
21 | logtostderr: "false"
22 | network-plugin: cni
23 | pod-infra-container-image: "pod-infra-container-image: {{ kube_image_repo }}/pause:3.7"
24 |
--------------------------------------------------------------------------------
/roles/kube-master/tasks/set-lb.yml:
--------------------------------------------------------------------------------
1 | # - name: Set cluster lb
2 | # shell: |
3 | # kubectl -n {{ item.ns }} get cm {{ item.cm }} -o yaml \
4 | # | sed 's#server: https://.*:6443#server: https://{{ cluster_lb }}:{{ cluster_lb_port }}#g' \
5 | # | kubectl -n {{ item.ns }} replace -f -
6 | # with_items:
7 | # - { "cm":"cluster-info","ns":"kube-public" }
8 | # - { "cm":"kube-proxy","ns":"kube-system" }
9 | # run_once: true
10 | # tags: change-lb
11 |
12 | # - name: Kube-proxy pods reload config
13 | # shell: |-
14 | # kubectl -n kube-system delete po -l k8s-app=kube-proxy --field-selector spec.nodeName=`hostname`
15 |
16 | # - name: Check kube-proxy pods running
17 | # shell: |-
18 | # kubectl -n kube-system get po -l k8s-app=kube-proxy --field-selector spec.nodeName=`hostname` | grep '1/1 *Running'
19 | # register: get_kube_proxy_pod_result
20 | # until: get_kube_proxy_pod_result is succeeded
21 | # retries: 10
22 | # delay: 3
--------------------------------------------------------------------------------
/cluster-create.yml:
--------------------------------------------------------------------------------
1 | - name: Common tasks for all
2 | hosts: all
3 | become: yes
4 | gather_facts: yes
5 | any_errors_fatal: yes
6 | # ignore_errors: yes
7 | vars_files:
8 | - vars/{{ env }}.yml
9 | roles:
10 | - { role: common, tags: common }
11 |
12 | - name: Build etcd cluster
13 | hosts: etcd
14 | become: yes
15 | gather_facts: no
16 | any_errors_fatal: yes
17 | vars_files:
18 | - vars/{{ env }}.yml
19 | roles:
20 | - { role: etcd, tags: etcd }
21 |
22 | - name: Deploy k8s master
23 | hosts: master
24 | become: yes
25 | gather_facts: yes
26 | any_errors_fatal: yes
27 | vars_files:
28 | - vars/{{ env }}.yml
29 | roles:
30 | - { role: kube-master, tags: kube-master }
31 | - { role: kube-network, tags: kube-network }
32 |
33 | - name: Deploy k8s node
34 | hosts: node
35 | become: yes
36 | gather_facts: yes
37 | any_errors_fatal: yes
38 | vars_files:
39 | - vars/{{ env }}.yml
40 | roles:
41 | - { role: kube-node, tags: kube-node }
42 |
--------------------------------------------------------------------------------
/roles/etcd/files/ca-config.json:
--------------------------------------------------------------------------------
1 | {
2 | "signing": {
3 | "default": {
4 | "expiry": "876000h"
5 | },
6 | "profiles": {
7 | "server": {
8 | "expiry": "876000h",
9 | "usages": [
10 | "signing",
11 | "key encipherment",
12 | "server auth",
13 | "client auth"
14 | ]
15 | },
16 | "client": {
17 | "expiry": "876000h",
18 | "usages": [
19 | "signing",
20 | "key encipherment",
21 | "client auth"
22 | ]
23 | },
24 | "peer": {
25 | "expiry": "876000h",
26 | "usages": [
27 | "signing",
28 | "key encipherment",
29 | "server auth",
30 | "client auth"
31 | ]
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/roles/common/files/clean-kubelet-log.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # kubelet config --log-dir=/data0/log/kube
3 | for i in {WARNING,INFO,ERROR,FATAL}; do
4 | num=$(ls -lt /data0/log/kube/*$i* | grep -v lrwxrwxrwx | wc -l)
5 | delete_num=$(expr $num - 5)
6 | if [ "$num" -gt 5 ]; then
7 | ls -lt /data0/log/kube/*$i* | grep -v lrwxrwxrwx | tail -n $delete_num | awk '{print $9}' | xargs rm
8 | else
9 | echo "$i is OK"
10 | fi
11 | done
12 |
13 | total_size=$(du -sm /data0/log/kube | awk '{print $1}')
14 | for level in {ERROR,WARNING,INFO}; do
15 | link_file=$(readlink /data0/log/kube/kubelet.${level})
16 | for file in $(ls -ltr /data0/log/kube/*$level* | grep -v "lrwxrwxrwx" | awk '{print $9}'); do
17 | file_name=$(basename $file)
18 | if [ x"$file_name" = x"$link_file" ]; then
19 | continue
20 | fi
21 | if [ $total_size -lt 9000 ]; then
22 | break
23 | fi
24 | size=$(du -sm $file | awk '{print $1}')
25 | rm -f $file
26 | total_size=$((total_size - size))
27 | done
28 | done
29 |
--------------------------------------------------------------------------------
/roles/kube-master/tasks/image.yml:
--------------------------------------------------------------------------------
1 | - name: Kubeadm {{ k8s_version }} images demo
2 | block:
3 | - name: Copy kubeadm {{ k8s_version }} images
4 | copy:
5 | src: files/kubeadm-{{ k8s_version }}.images.tar.gz
6 | dest: /tmp/kubeadm-{{ k8s_version }}.images.tar.gz
7 | owner: root
8 | group: root
9 | mode: 0755
10 | - name: Load kubeadm {{ k8s_version }} images
11 | shell: docker load -i /tmp/kubeadm-{{ k8s_version }}.images.tar.gz
12 | tags: load_images
13 | when: container_runtime == "docker"
14 |
15 | - name: Kubeadm {{ k8s_version }} images demo
16 | block:
17 | - name: Copy kubeadm {{ k8s_version }} images
18 | copy:
19 | src: files/kubeadm-{{ k8s_version }}.images.tar.gz
20 | dest: /tmp/kubeadm-{{ k8s_version }}.images.tar.gz
21 | owner: root
22 | group: root
23 | mode: 0755
24 | - name: Load kubeadm {{ k8s_version }} images
25 | shell: ctr -n k8s.io images import /tmp/kubeadm-{{ k8s_version }}.images.tar.gz
26 | tags: load_images
27 | when: container_runtime == "containerd"
--------------------------------------------------------------------------------
/roles/kube-node/tasks/config.yml:
--------------------------------------------------------------------------------
1 | # set admin.config to node
2 | - name: Get admin.conf from first master
3 | fetch:
4 | src: /etc/kubernetes/admin.conf
5 | dest: /tmp/{{ groups.master | first }}/admin.conf
6 | flat: yes
7 | delegate_to: "{{ groups.master | first }}"
8 | run_once: true
9 |
10 | # - name: Set lb address in admin.conf
11 | # replace:
12 | # path: /tmp/{{ groups.master | first }}/admin.conf
13 | # regexp: '^( server: https://).*:6443$'
14 | # replace: '\g<1>{{ cluster_lb }}:{{ cluster_lb_port }}'
15 | # delegate_to: 127.0.0.1
16 | # run_once: true
17 |
18 | - name: Copy admin.conf to node
19 | copy:
20 | src: /tmp/{{ groups.master | first }}/admin.conf
21 | dest: /root/.kube/config
22 |
23 | - name: Enable kubelet
24 | systemd:
25 | name: kubelet
26 | enabled: yes
27 | daemon_reload: yes
28 |
29 | - name: Ensure node's kubelet is running
30 | shell: |
31 | systemctl is-active kubelet
32 | register: check_kubelet_result
33 | until: check_kubelet_result is succeeded
34 | retries: 5
35 | delay: 3
36 |
37 | - name: Get node
38 | shell: kubectl get node `hostname`
39 | register: get_node_result
40 | until: get_node_result is success
41 | retries: 5
42 | delay: 2
--------------------------------------------------------------------------------
/cluster-destroy.yml:
--------------------------------------------------------------------------------
1 | - hosts: master:node
2 | become: yes
3 | gather_facts: no
4 | tags: k8s
5 | tasks:
6 | - name: Delete node
7 | shell: "kubectl delete node `hostname`"
8 | ignore_errors: yes
9 | - name: Kubeadm reset
10 | shell: kubeadm reset -f
11 | - name: Umount overlay shm
12 | shell: df -h | egrep 'docker|kubelet|containerd'|awk '{print$NF}'|xargs -r umount
13 | - name: Stop services
14 | systemd:
15 | name: "{{ item }}"
16 | state: stopped
17 | enabled: no
18 | daemon_reload: yes
19 | with_items:
20 | - dockerd
21 | - containerd
22 | - kubelet
23 | ignore_errors: yes
24 |
25 | - hosts: etcd
26 | become: yes
27 | gather_facts: no
28 | tags: etcd
29 | tasks:
30 | - name: Stop etcd
31 | systemd:
32 | name: etcd
33 | state: stopped
34 | enabled: no
35 |
36 | - name: Delete etcd data
37 | file:
38 | path: "{{ item }}"
39 | state: absent
40 | with_items:
41 | - "{{ etcd_cert_dir }}"
42 | - "{{ etcd_data_dir }}"
43 |
44 | - hosts: all
45 | become: yes
46 | gather_facts: no
47 | tasks:
48 | - shell: journalctl --flush && journalctl --vacuum-time=1s
49 |
--------------------------------------------------------------------------------
/cluster-reduce.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - hosts: node
3 | become: yes
4 | gather_facts: no
5 | vars_files:
6 | - vars/{{ env }}.yml
7 | tasks:
8 | - name: Add offline taint
9 | shell: kubectl taint node `hostname` Task=offline:NoExecute --overwrite
10 |
11 | - name: Drain node
12 | shell: kubectl drain `hostname`
13 | ignore_errors: yes
14 |
15 | - name: Check pod list
16 | shell: kubectl get pod -o wide --all-namespaces --field-selector spec.nodeName=`hostname` |grep -v NAME|wc -l
17 | register: all_pod_list
18 | delegate_to: "{{ ansible_play_hosts | first }}"
19 | run_once: true
20 | retries: 6
21 | delay: 5
22 | # kube-proxy
23 | until: all_pod_list.stdout|int == 1
24 |
25 | - name: Delete node
26 | shell: "kubectl delete node `hostname`"
27 | ignore_errors: yes
28 |
29 | - name: Kubeadm reset
30 | shell: kubeadm reset -f
31 |
32 | - name: Umount overlay shm
33 | shell: df -h | egrep 'docker|kubelet|containerd'|awk '{print$NF}'|xargs -r umount
34 |
35 | - name: Stop services
36 | systemd:
37 | name: "{{ item }}"
38 | state: stopped
39 | enabled: no
40 | daemon_reload: yes
41 | with_items:
42 | - dockerd
43 | - containerd
44 | - kubelet
45 | ignore_errors: yes
--------------------------------------------------------------------------------
/roles/common/tasks/sa.yml:
--------------------------------------------------------------------------------
1 | # rc
2 | - name: Deploy rc scripts
3 | copy:
4 | src: "{{ item }}"
5 | dest: "/etc/rc.d/rc.sre/{{ item }}"
6 | mode: 0755
7 | owner: root
8 | group: root
9 | with_items:
10 | - set-conntrack.sh
11 | - set-nice.sh
12 | # - set-cgroupv2.sh
13 |
14 | - name: Deploy rc.local
15 | copy:
16 | src: "rc.local"
17 | dest: "/etc/rc.d/rc.local"
18 | mode: "0755"
19 | owner: root
20 | group: root
21 |
22 | # sysctl
23 | - name: Copy sysctl.conf
24 | copy:
25 | src: sysctl.conf
26 | dest: /etc/sysctl.conf
27 | mode: 0644
28 | owner: root
29 | group: root
30 | checksum: 7c8f79e08cba887996772baf2a77f6886968f19e
31 |
32 | - name: Sysctl take effect
33 | shell: sysctl -p
34 |
35 | # other
36 | - name: Add sudoers for dev user
37 | copy:
38 | src: dev-sudoers
39 | dest: /etc/sudoers.d/dev-sudoers
40 | mode: 0644
41 | owner: root
42 | group: root
43 |
44 | - name: Copy kubelet logrotate script
45 | copy:
46 | src: clean-kubelet-log.sh
47 | dest: /etc/cron.daily/clean-kubelet-log.sh
48 | mode: 0755
49 | owner: root
50 | group: root
51 |
52 | - name: Adjust syslog logrotate
53 | copy:
54 | src: syslog
55 | dest: /etc/logrotate.d/syslog
56 | owner: root
57 | group: root
58 | mode: 0644
59 | checksum: 434fdb792ed12e6d18cc344dae798ed06a1dc784
--------------------------------------------------------------------------------
/roles/kube-node/tasks/join.yml:
--------------------------------------------------------------------------------
1 | # - name: Gather master network facts
2 | # setup:
3 | # gather_subset:
4 | # - '!all'
5 | # - '!any'
6 | # - network
7 | # delegate_to: "{{ item }}"
8 | # delegate_facts: true
9 | # when: hostvars[item].ansible_facts.eth0 is not defined
10 | # with_items: "{{ groups.master }}"
11 | # run_once: true
12 |
13 | # - debug:
14 | # msg: "master {{ groups.master|first }} ipv4: {{ hostvars[ groups.master|first ].ansible_facts.default_ipv4.address }}"
15 |
16 | # - name: New join token from first master
17 | # shell: kubeadm token create
18 | # register: token
19 | # delegate_to: "{{ groups.master | first }}"
20 | # run_once: true
21 |
22 | # - name: Copy join config
23 | # template:
24 | # src: "kubeadm-{{ k8s_version }}.j2"
25 | # dest: /tmp/kubeadm-{{ k8s_version }}.yml
26 | # trim_blocks: yes
27 | # lstrip_blocks: yes
28 | # vars:
29 | # kubeadm_token: "{{ token.stdout }}"
30 |
31 | # - name: Kubeadm join
32 | # shell: kubeadm join --config=/tmp/kubeadm-{{ k8s_version }}.yml
33 | # register: join_result
34 |
35 | # - debug:
36 | # msg: "{{ hostvars[inventory_hostname] }} join result: {{ join_result.stdout }}"
37 |
38 | - name: Get token from master
39 | shell: kubeadm token create --print-join-command
40 | register: token
41 | delegate_to: "{{ groups.master | first }}"
42 | run_once: true
43 |
44 | - name: Join master
45 | shell: "{{ token.stdout }}"
46 | register: join_result
47 |
48 | - debug:
49 | msg: "{{ inventory_hostname }} join result: {{ join_result.stdout }}"
--------------------------------------------------------------------------------
/roles/etcd/templates/etcd-env.j2:
--------------------------------------------------------------------------------
1 | ETCD_NAME={{ ansible_facts.nodename }}
2 | ETCD_INITIAL_CLUSTER={% for host in groups.etcd %}{{ hostvars[host].ansible_facts.nodename }}=https://{{ hostvars[host].ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }}{{ ',' if not loop.last else '\n' }}{% endfor %}
3 | ETCD_INITIAL_CLUSTER_STATE=new
4 | ETCD_FORCE_NEW_CLUSTER=true
5 |
6 |
7 | # Peer configuration
8 | ETCD_INITIAL_ADVERTISE_PEER_URLS=https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }}
9 | ETCD_LISTEN_PEER_URLS=https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }}
10 |
11 | ETCD_CLIENT_CERT_AUTH=true
12 | ETCD_PEER_CERT_FILE={{ etcd_cert_dir }}/peer.pem
13 | ETCD_PEER_KEY_FILE={{ etcd_cert_dir }}/peer-key.pem
14 | ETCD_PEER_TRUSTED_CA_FILE={{ etcd_cert_dir }}/ca.pem
15 |
16 | # Client/server configuration
17 | ETCD_ADVERTISE_CLIENT_URLS=https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_port }}
18 | ETCD_LISTEN_CLIENT_URLS=https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_port }},https://127.0.0.1:2379
19 |
20 | ETCD_PEER_CLIENT_CERT_AUTH=true
21 | ETCD_CERT_FILE={{ etcd_cert_dir }}/server.pem
22 | ETCD_KEY_FILE={{ etcd_cert_dir }}/server-key.pem
23 | ETCD_TRUSTED_CA_FILE={{ etcd_cert_dir }}/ca.pem
24 |
25 | # Other
26 | ETCD_DATA_DIR={{ etcd_data_dir }}
27 | ETCD_STRICT_RECONFIG_CHECK=true
28 |
29 | # ExtraEnvs
30 | ETCD_CLIENT_CERT_AUTH=true
31 | ETCD_ENABLE_PPROF=true
32 | ETCD_EXPERIMENTAL_BACKEND_BBOLT_FREELIST_TYPE=map
33 | ETCD_EXPERIMENTAL_ENABLE_LEASE_CHECKPOINT=true
34 | ETCD_LOGGER=zap
35 | ETCD_PEER_CLIENT_CERT_AUTH=true
36 | ETCD_PRE_VOTE=true
37 | ETCD_QUOTA_BACKEND_BYTES=17179869184
38 |
--------------------------------------------------------------------------------
/vars/dev.yml:
--------------------------------------------------------------------------------
1 | env: dev
2 | insecure_registries:
3 | - registry.docker-cn.com
4 | kube_image_repo: "registry.aliyuncs.com/google_containers"
5 |
6 | docker_log_opts_max_file: 5
7 |
8 | kernel_version: 4.19.95-35
9 |
10 | cluster_name: dev-k8s
11 | cluster_lb: 1.1.1.1
12 | cluster_lb_port: 8888
13 | cluster_network_type: flannel
14 | system_reserved_cpu: 500m
15 | system_reserved_memory: 200m
16 | k8s_version: v1.24.0
17 | kube_packages:
18 | "v1.24.0":
19 | - kubelet-1.24.0-0
20 | - kubectl-1.24.0-0
21 | - kubeadm-1.24.0-0
22 | # 已经提前通过ansible安装, 不写入playbook
23 | kube_rpm_packages:
24 | "v1.24.0":
25 | - kubelet-1.24.0-0.x86_64.rpm
26 | - kubectl-1.24.0-0.x86_64.rpm
27 | - kubeadm-1.24.0-0.x86_64.rpm
28 | - kubernetes-cni-1.2.0-0.x86_64.rpm
29 | - cri-tools-1.19.0-0.x86_64.rpm
30 | etcd_count: 3
31 | master_count: 1
32 | container_runtime: containerd # docker
33 | docker_version: docker-ce-20.10.10-3.el7
34 | containerd_version: 1.4.12-3.1.el7
35 |
36 |
37 | # note: etcd assets download, https://github.com/etcd-io/etcd/releases?page=7
38 | https: yes
39 | etcd_cert_dir: /etc/etcd/certs
40 | etcdctl_env:
41 | ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
42 | ETCDCTL_CERT: "{{ etcd_cert_dir }}/server.pem"
43 | ETCDCTL_KEY: "{{ etcd_cert_dir }}/server-key.pem"
44 | etcd_version_dict:
45 | v1.24.0: v3.5.16
46 | # k8s version define etcd version
47 | etcd_version: "{{ etcd_version_dict[k8s_version] }}"
48 | etcd_tar_checksum:
49 | v3.4.7: 6a1b6443959f1ae0f2a883f678fef6c9afaecf1a
50 | v3.5.16: b4bf00b4adae87edba5a2aa3d7f2bb94deaed95a
51 | etcd_data_dir: /data0/etcd-cluster
52 | etcd_listen_port: 2379
53 | etcd_listen_peer_port: 2380
54 | etcd_service_name: etcd
55 |
--------------------------------------------------------------------------------
/roles/etcd/templates/etcd-service.j2:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=etcd
3 | After=network.target
4 |
5 | [Service]
6 | Type=notify
7 | WorkingDirectory={{ etcd_data_dir }}
8 | LimitNOFILE=655350
9 | Restart=on-failure
10 | ExecStart=/usr/local/bin/etcd \
11 | --name={{ ansible_facts.hostname }} \
12 | --advertise-client-urls={{ 'https' if https|bool else 'http' }}://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_port }} \
13 | --listen-client-urls={{ 'https' if https|bool else 'http' }}://0.0.0.0:{{ etcd_listen_port }} \
14 | --initial-advertise-peer-urls=https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }} \
15 | --listen-peer-urls=https://0.0.0.0:{{ etcd_listen_peer_port }} \
16 | --initial-cluster-token={{ cluster_name }} \
17 | --initial-cluster={% for host in groups.etcd %}{{ hostvars[host].ansible_facts.hostname }}=https://{{ hostvars[host].ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }}{{ ',' if not loop.last else '' }}{% endfor %} \
18 | --initial-cluster-state=new \
19 | {% if https | bool %}
20 | --cert-file={{ etcd_cert_dir }}/server.pem \
21 | --key-file={{ etcd_cert_dir }}/server-key.pem \
22 | --client-cert-auth \
23 | {% endif %}
24 | --trusted-ca-file={{ etcd_cert_dir }}/ca.pem \
25 | --peer-cert-file={{ etcd_cert_dir }}/peer.pem \
26 | --peer-key-file={{ etcd_cert_dir }}/peer-key.pem \
27 | --peer-client-cert-auth \
28 | --peer-trusted-ca-file={{ etcd_cert_dir }}/ca.pem \
29 | --quota-backend-bytes=17179869184 \
30 | --logger=zap \
31 | --pre-vote=true \
32 | --experimental-backend-bbolt-freelist-type=map \
33 | --experimental-enable-lease-checkpoint=true \
34 | --data-dir=/data0/etcd-cluster
35 |
36 | [Install]
37 | WantedBy=multi-user.target
38 |
--------------------------------------------------------------------------------
/roles/kube-master/files/apiserver-audit-policy.yml:
--------------------------------------------------------------------------------
1 | apiVersion: audit.k8s.io/v1
2 | kind: Policy
3 |
4 | rules:
5 | - level: None
6 | verbs: ["create","update","delete","patch"]
7 | resources:
8 | - group: ""
9 | resources: ["apiservices/status", "namespaces/status", "nodes/status", "persistentvolumes/status", "persistentVolumeClaims/status", "pods/status", "resourceQuotas/status", "replicationControllers/status", "services/status"]
10 | - group: "extensions"
11 | resources: ["apiservices/status", "namespaces/status", "nodes/status", "persistentvolumes/status", "persistentVolumeClaims/status", "pods/status", "resourceQuotas/status", "replicationControllers/status", "services/status"]
12 | - group: "apiregistration.k8s.io"
13 | resources: ["apiservices/status", "namespaces/status", "nodes/status", "persistentvolumes/status", "persistentVolumeClaims/status", "pods/status", "resourceQuotas/status", "replicationControllers/status", "services/status"]
14 | - group: "apps"
15 | resources: ["apiservices/status", "namespaces/status", "nodes/status", "persistentvolumes/status", "persistentVolumeClaims/status", "pods/status", "resourceQuotas/status", "replicationControllers/status", "services/status"]
16 | - group: "batch"
17 | resources: ["apiservices/status", "namespaces/status", "nodes/status", "persistentvolumes/status", "persistentVolumeClaims/status", "pods/status", "resourceQuotas/status", "replicationControllers/status", "services/status"]
18 |
19 | - level: None
20 | resources:
21 | - group: ""
22 | resources: ["events"]
23 | - group: "extensions"
24 | resources: ["events"]
25 | - group: "apiregistration.k8s.io"
26 | resources: ["events","tokenreviews"]
27 | - group: "authentication.k8s.io"
28 | resources: ["tokenreviews"]
29 |
30 | - level: RequestResponse
31 | verbs: ["create","delete","update","patch"]
32 |
33 |
--------------------------------------------------------------------------------
/roles/etcd/tasks/service.yml:
--------------------------------------------------------------------------------
1 | # centos etcd service config
2 | - name: Create etcd data dir
3 | file:
4 | path: "{{ item }}"
5 | state: directory
6 | with_items:
7 | - /etc/etcd
8 | - "{{ etcd_data_dir }}"
9 |
10 | - name: Copy etcd service env
11 | template:
12 | dest: /etc/etcd/etcd.conf.yml
13 | src: etcd-conf.j2
14 | trim_blocks: yes
15 |
16 | - name: Copy etcd service config
17 | copy:
18 | src: etcd-conf.service
19 | dest: /etc/systemd/system/{{ etcd_service_name }}.service
20 | owner: root
21 | group: root
22 | mode: 0755
23 | # notify: Restart etcd service, handler executes after all tasks are completed
24 |
25 | - name: Copy etcd tar.gz
26 | copy:
27 | src: files/etcd-{{ etcd_version }}-linux-amd64.tar.gz
28 | dest: /tmp/
29 | checksum: "{{ etcd_tar_checksum[etcd_version] }}"
30 |
31 | - name: Unarchive etcd bin
32 | unarchive:
33 | remote_src: yes
34 | src: /tmp/etcd-{{ etcd_version }}-linux-amd64.tar.gz
35 | dest: /usr/local/bin/
36 | owner: root
37 | group: root
38 | mode: 0755
39 | # 防止解压缩嵌套目录, 解压到/usr/local/bin目录中
40 | extra_opts:
41 | - --strip-components=1
42 | - etcd-{{ etcd_version }}-linux-amd64/etcd
43 | - etcd-{{ etcd_version }}-linux-amd64/etcdctl
44 |
45 | - name: Start etcd
46 | systemd:
47 | name: "{{ etcd_service_name }}"
48 | state: started
49 | enabled: yes
50 | daemon_reload: yes
51 |
52 | - name: Check etcd service
53 | shell: systemctl is-active {{ etcd_service_name }} && systemctl is-enabled {{ etcd_service_name }}
54 | retries: 5
55 | delay: 3
56 |
57 | - name: Check etcd health
58 | shell: ETCDCTL_API=3 /usr/local/bin/etcdctl endpoint health --endpoints https://127.0.0.1:{{ etcd_listen_port | default('2379') }}
59 | register: etcd_health_result
60 | retries: 5
61 | delay: 3
62 | environment: "{{ etcdctl_env }}"
63 |
64 | - name: Debug etcd health info
65 | debug:
66 | msg: "{{ etcd_health_result }}"
67 |
--------------------------------------------------------------------------------
/roles/common/files/sysctl.conf:
--------------------------------------------------------------------------------
1 | # sysctl.conf - Set default system configuration
2 | # Version: v1.0.0
3 | fs.aio-max-nr = 1048576
4 | fs.file-max = 67108864
5 | fs.inotify.max_user_instances = 1024
6 | kernel.core_uses_pid = 1
7 | kernel.hung_task_panic = 0
8 | kernel.hung_task_timeout_secs = 28
9 | kernel.msgmax = 655360
10 | kernel.msgmnb = 655360
11 | kernel.numa_balancing = 0
12 | kernel.panic = 5
13 | kernel.perf_event_paranoid = 1
14 | kernel.printk = 5
15 | kernel.shmall = 4294967296
16 | kernel.shmmax = 68719476736
17 | kernel.softlockup_panic = 0
18 | kernel.sysrq = 0
19 | kernel.watchdog_thresh = 50
20 | net.bridge.bridge-nf-call-ip6tables = 1
21 | net.bridge.bridge-nf-call-iptables = 1
22 | net.core.netdev_max_backlog = 262144
23 | net.core.rmem_default = 8388608
24 | net.core.rmem_max = 16777216
25 | net.core.somaxconn = 16384
26 | net.core.wmem_default = 8388608
27 | net.core.wmem_max = 16777216
28 | net.ipv4.conf.all.rp_filter = 0
29 | net.ipv4.conf.default.accept_source_route = 0
30 | net.ipv4.conf.default.rp_filter = 0
31 | net.ipv4.ip_forward = 1
32 | net.ipv4.ip_local_port_range = 32768 65500
33 | net.ipv4.ip_local_reserved_ports = 1988,2001
34 | net.ipv4.neigh.default.gc_thresh1 = 1024
35 | net.ipv4.neigh.default.gc_thresh2 = 2048
36 | net.ipv4.neigh.default.gc_thresh3 = 4096
37 | net.ipv4.tcp_abort_on_overflow = 0
38 | net.ipv4.tcp_dsack = 1
39 | net.ipv4.tcp_early_retrans = 3
40 | net.ipv4.tcp_fin_timeout = 1
41 | net.ipv4.tcp_max_orphans = 3276800
42 | net.ipv4.tcp_max_syn_backlog = 819200
43 | net.ipv4.tcp_max_tw_buckets = 16384
44 | net.ipv4.tcp_mem = 786432 2097152 4194304
45 | net.ipv4.tcp_retrans_collapse = 0
46 | net.ipv4.tcp_rmem = 4096 65536 8388608
47 | net.ipv4.tcp_sack = 1
48 | net.ipv4.tcp_synack_retries = 1
49 | net.ipv4.tcp_syncookies = 1
50 | net.ipv4.tcp_syn_retries = 1
51 | net.ipv4.tcp_timestamps = 0
52 | net.ipv4.tcp_tw_reuse = 0
53 | net.ipv4.tcp_window_scaling = 1
54 | net.ipv4.tcp_wmem = 4096 65536 8388608
55 | vm.dirty_background_ratio = 1
56 | vm.dirty_expire_centisecs = 5
57 | vm.max_map_count = 262144
58 | vm.swappiness = 0
59 | vm.dirty_ratio = 30
60 | kernel.sched_min_granularity_ns = 10000000
61 | fs.inotify.max_user_watches = 524288
62 |
--------------------------------------------------------------------------------
/roles/common/tasks/prepare.yml:
--------------------------------------------------------------------------------
1 | - name: Check inventory node groups
2 | fail:
3 | msg: master, node, etcd required in host inventory file
4 | when: not ('etcd' in groups and 'master' in groups and 'node' in groups)
5 | delegate_to: localhost
6 | become: false
7 | run_once: true
8 |
9 | - name: Check hostname
10 | fail:
11 | msg: |
12 | check hostname please, if correct flush gather cache with --flush-cache
13 | when: ansible_facts.hostname != inventory_hostname_short
14 |
15 | - name: Check kernel version
16 | fail:
17 | msg: "{{ kernel_version }} expected, {{ ansible_kernel }} in fact"
18 | when: kernel_version != ansible_kernel
19 |
20 | - name: Swapoff
21 | shell: swapoff -a
22 | when: ansible_swaptotal_mb > 0
23 |
24 | - name: Disable SELinux
25 | selinux:
26 | state: disabled
27 |
28 | - name: Stop firewalld
29 | systemd:
30 | name: firewalld
31 | state: stopped
32 | enabled: no
33 |
34 | - name: Install ipvs ipvsadm
35 | yum:
36 | name:
37 | - ipset
38 | - ipvsadm
39 | state: present
40 | update_cache: yes
41 |
42 | - name: Add ipvs modules config
43 | copy:
44 | src: ipvs.modules
45 | dest: /etc/sysconfig/modules/ipvs.modules
46 | mode: 0755
47 | owner: root
48 | group: root
49 |
50 | - name: Task ipvs modules effect
51 | shell: /etc/sysconfig/modules/ipvs.modules
52 | register: ipvs_modules
53 | failed_when: ipvs_modules.rc | int != 0
54 |
55 | - name: Create desired dirs
56 | file:
57 | path: "{{ item }}"
58 | state: directory
59 | mode: "0755"
60 | with_items:
61 | - /usr/local/kernel
62 | - /usr/local/sre
63 | - /etc/rc.d/rc.sre
64 | - /root/.kube
65 | - /data0/kubelet
66 | - /data0/log/kube
67 | - /data0/log/apiserver
68 | - /etc/kubernetes
69 | - /etc/kubernetes/manifests
70 | - /etc/kubernetes/pki
71 | - /etc/kubernetes/pki/conf
72 | - /etc/kubernetes/pki/etcd
73 | - /etc/docker/
74 | - /etc/containerd
75 |
76 | - name: Install basic tools
77 | yum:
78 | name:
79 | - jq
80 | - curl
81 | - cfssl
82 | - ntp
83 | - socat
84 | - conntrack
85 | state: present
86 | update_cache: yes
87 | register: yum_result
88 | retries: 3
89 | delay: 2
90 | until: yum_result is success
--------------------------------------------------------------------------------
/roles/common/tasks/container-runtime.yml:
--------------------------------------------------------------------------------
1 | - name: Install docker runtime
2 | block:
3 | - name: Install docker
4 | yum:
5 | name: docker-ce-{{ docker_version }}
6 | state: present
7 | update_cache: yes
8 |
9 | - name: Docker config daemon.json
10 | template:
11 | src: docker-daemon.j2
12 | dest: /etc/docker/daemon.json
13 | trim_blocks: yes
14 | lstrip_blocks: yes
15 |
16 | - name: Restart docker
17 | systemd:
18 | name: docker
19 | state: restarted
20 | daemon_reload: yes
21 | enabled: yes
22 |
23 | - name: Check docker running
24 | shell: systemctl is-active docker
25 | register: docker_active_result
26 | retries: 6
27 | delay: 5
28 | until: docker_active_result.stdout == 'active'
29 |
30 | - name: Load pause images
31 | shell: docker load -i /tmp/infra-pause.3.7.image.tar.gz
32 | when: container_runtime == "docker"
33 |
34 | - name: Install containerd runtime
35 | block:
36 | - name: Install containerd
37 | yum:
38 | name: containerd.io-{{ containerd_version }}
39 | state: present
40 | update_cache: yes
41 |
42 | - name: Copy containerd toml
43 | template:
44 | src: containerd.toml.j2
45 | dest: /etc/containerd/config.toml
46 | trim_blocks: yes
47 | lstrip_blocks: yes
48 |
49 | - name: Restart containerd
50 | systemd:
51 | name: containerd
52 | state: restarted
53 | daemon_reload: yes
54 | enabled: yes
55 |
56 | - name: Check containerd running
57 | shell: systemctl is-active containerd
58 | register: containerd_active_result
59 | retries: 6
60 | delay: 5
61 | until: containerd_active_result.stdout == 'active'
62 |
63 | - name: Load pause images
64 | shell: ctr -n k8s.io images import /tmp/infra-pause.3.7.image.tar.gz
65 | when: container_runtime == "containerd"
66 |
67 | # - name: Copy crictl
68 | # copy:
69 | # src: files/crictl-v1.32.0-linux-amd64.tar.gz
70 | # dest: /tmp/
71 |
72 | # - name: Install crictl
73 | # shell: tar -zxvf crictl-v1.32.0-linux-amd64.tar.gz -C /usr/local/bin && crictl config runtime-endpoint "unix:///run/containerd/containerd.sock"
74 | # args:
75 | # chdir: /tmp/
76 |
--------------------------------------------------------------------------------
/roles/kube-master/tasks/init.yml:
--------------------------------------------------------------------------------
1 | - name: Gather etcd network facts
2 | setup:
3 | gather_subset:
4 | - '!all'
5 | - '!any'
6 | - network
7 | delegate_to: "{{ item }}"
8 | delegate_facts: true
9 | when: hostvars[item].ansible_facts.eth0 is not defined
10 | with_items: "{{ groups.etcd }}"
11 | run_once: true
12 |
13 | - name: Copy kubeadm init config template
14 | template:
15 | src: "kubeadm-{{ k8s_version }}.j2"
16 | dest: /tmp/kubeadm-{{ k8s_version }}.yml
17 |
18 | - name: Copy kubeadm init config template
19 | copy:
20 | src: "apiserver-audit-policy.yml"
21 | dest: /etc/kubernetes/conf/apiserver-audit-policy.yml
22 | mode: 0644
23 | owner: root
24 | group: root
25 |
26 | - name: Init first master node
27 | block:
28 | - name: Copy etcd certs to first master node
29 | unarchive:
30 | src: /tmp/{{ groups.etcd | first }}/etcd-certs.tar.gz
31 | dest: /etc/kubernetes/pki/etcd/
32 | extra_opts:
33 | - ca.pem
34 | - client.pem
35 | - client-key.pem
36 |
37 | - name: Kubeadm init on first master node
38 | shell: kubeadm init --config=/tmp/kubeadm-{{ k8s_version }}.yml
39 | register: kubeadm_first_init_result
40 |
41 | - debug: var=kubeadm_first_init_result.stdout verbosity=2
42 |
43 | - name: Tar certs on first master node
44 | archive:
45 | path: /etc/kubernetes/pki/*
46 | dest: /tmp/master-certs.tar.gz
47 |
48 | - name: Fetch certs on first master node
49 | fetch:
50 | src: /tmp/master-certs.tar.gz
51 | dest: /tmp/{{ groups.master | first }}/
52 | flat: true
53 | when: inventory_hostname == groups.master|first
54 |
55 | - name: Init other master nodes
56 | block:
57 | - name: Copy certs to other master nodes
58 | unarchive:
59 | src: /tmp/{{ groups.master | first }}/master-certs.tar.gz
60 | dest: /etc/kubernetes/pki/
61 |
62 | - name: Kubeadm init on other master nodes
63 | shell: kubeadm init --config=/tmp/kubeadm-{{ k8s_version }}.yml
64 | when: inventory_hostname != groups.master|first
65 |
66 | - name: Enable kubelet
67 | systemd:
68 | name: kubelet
69 | enabled: yes
70 | daemon_reload: yes
71 |
72 | - name: Check kubelet running
73 | shell: systemctl is-active kubelet
74 | register: kubelet_active_result
75 | retries: 6
76 | delay: 5
77 | until: kubelet_active_result.stdout == 'active'
78 |
79 | - name: Copy admin.conf to .kube/config
80 | copy:
81 | src: /etc/kubernetes/admin.conf
82 | dest: /root/.kube/config
83 | remote_src: true
84 | owner: root
85 | group: root
--------------------------------------------------------------------------------
/roles/etcd/tasks/cert.yml:
--------------------------------------------------------------------------------
1 | - name: Create dirs for etcd cert and env
2 | file:
3 | path: "{{ etcd_cert_dir }}"
4 | state: directory
5 |
6 | - name: Check etcd certificate exists
7 | shell: ls -l *.pem|wc -l
8 | args:
9 | chdir: "{{ etcd_cert_dir }}"
10 | register: pem_count
11 | failed_when: pem_count.stdout | int != 0
12 | tags: check_exist_etcd_pem
13 |
14 | - name: Yum install cfssl
15 | yum:
16 | name: cfssl
17 | state: latest
18 |
19 | - name: Gen etcd certs on etcd first node
20 | block:
21 | - name: Copy certs configs
22 | copy:
23 | src: "{{ item }}"
24 | dest: "{{ etcd_cert_dir }}"
25 | with_items:
26 | - ca-csr.json
27 | - ca-config.json
28 | - client-csr.json
29 |
30 | - name: Gen etcd CA certs
31 | shell: cfssl gencert -initca ca-csr.json | cfssljson -bare ca
32 | args:
33 | chdir: "{{ etcd_cert_dir }}"
34 |
35 | - name: Gen etcd client certs
36 | shell: |
37 | cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client client-csr.json | cfssljson -bare client
38 | args:
39 | chdir: "{{ etcd_cert_dir }}"
40 |
41 | - name: Tar etcd certs on etcd first node
42 | archive:
43 | path:
44 | - "{{ etcd_cert_dir }}/ca-config.json"
45 | - "{{ etcd_cert_dir }}/ca.pem"
46 | - "{{ etcd_cert_dir }}/ca-key.pem"
47 | - "{{ etcd_cert_dir }}/client.pem"
48 | - "{{ etcd_cert_dir }}/client-key.pem"
49 | dest: /tmp/etcd-certs.tar.gz
50 | remove: no
51 |
52 | - name: Fetch certs from etcd first node
53 | fetch:
54 | src: /tmp/etcd-certs.tar.gz
55 | dest: /tmp/{{ groups.etcd | first }}/
56 | flat: yes
57 | delegate_to: "{{ groups.etcd | first }}"
58 | run_once: true
59 |
60 | - name: Copy certs from local to other etcd nodes
61 | unarchive:
62 | src: /tmp/{{ groups.etcd | first }}/etcd-certs.tar.gz
63 | dest: "{{ etcd_cert_dir }}/"
64 | when: inventory_hostname != groups.etcd|first
65 |
66 | - name: Copy peer config template
67 | template:
68 | src: etcd-cluster-csr.j2
69 | dest: "{{ etcd_cert_dir }}/etcd-cluster-csr.json"
70 | tags: template
71 |
72 | - name: Gen etcd server and peer certs using cfssl
73 | shell: "cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile={{ item }} etcd-cluster-csr.json | cfssljson -bare {{ item }}"
74 | args:
75 | chdir: "{{ etcd_cert_dir }}"
76 | with_items:
77 | - server
78 | - peer
79 |
80 | - name: Chmod etcd pem
81 | shell: chmod 0644 *.pem
82 | args:
83 | chdir: "{{ etcd_cert_dir }}"
--------------------------------------------------------------------------------
/roles/kube-master/templates/kubeadm-v1.24.0.j2:
--------------------------------------------------------------------------------
1 | ---
2 | # note: https://kubernetes.io/zh-cn/docs/reference/config-api/kubeadm-config.v1beta4/
3 | apiVersion: kubeadm.k8s.io/v1beta3
4 | kind: InitConfiguration
5 | nodeRegistration:
6 | criSocket: unix:///var/run/containerd/containerd.sock
7 | imagePullPolicy: IfNotPresent
8 | taints:
9 | - effect: NoSchedule
10 | key: node-role.kubernetes.io/master
11 | kubeletExtraArgs:
12 | log-dir: /data0/log/kube
13 | logtostderr: "false"
14 | pod-infra-container-image: {{ kube_image_repo }}/pause:3.7
15 |
16 | ---
17 | # kubeadm cluster config
18 | apiVersion: kubeadm.k8s.io/v1beta3
19 | certificatesDir: /etc/kubernetes/pki
20 | kind: ClusterConfiguration
21 | kubernetesVersion: {{ k8s_version }}
22 | clusterName: {{ cluster_name }}
23 | imageRepository: {{ kube_image_repo }}
24 | networking:
25 | dnsDomain: "cluster.local"
26 | serviceSubnet: "10.96.0.0/12"
27 | podSubnet: "10.244.0.0/16"
28 |
29 | etcd:
30 | external:
31 | endpoints:
32 | {% for host in groups.etcd %}
33 | - https://{{ hostvars[host].ansible_facts.default_ipv4.address }}:2379
34 | {% endfor %}
35 | caFile: /etc/kubernetes/pki/etcd/ca.pem
36 | certFile: /etc/kubernetes/pki/etcd/client.pem
37 | keyFile: /etc/kubernetes/pki/etcd/client-key.pem
38 |
39 | apiServer:
40 | certSANs:
41 | {% for host in groups.master %}
42 | - {{ hostvars[host].ansible_facts.hostname }}
43 | {% if hostvars[host].ansible_facts.hostname != hostvars[host].ansible_facts.nodename %}
44 | - {{ hostvars[host].ansible_facts.nodename }}
45 | {% endif %}
46 | - {{ hostvars[host].ansible_facts.default_ipv4.address }}
47 | {% endfor %}
48 | - {{ cluster_lb }}
49 | # https://kubernetes.io/zh-cn/docs/reference/command-line-tools-reference/kube-apiserver/#options
50 | extraArgs: # apiserver的启动参数
51 | audit-log-path: /data0/log/apiserver/audit.log
52 | audit-policy-file: /etc/kubernetes/conf/apiserver-audit-policy.yml
53 | audit-log-maxage: "5"
54 | audit-log-maxbackup: "5"
55 | audit-log-maxsize: "100"
56 | extraVolumes: # apiserver需要的额外挂载, 日志目录和日志配置
57 | - name: k8s-conf
58 | hostPath: /etc/kubernetes/conf
59 | mountPath: /etc/kubernetes/conf
60 | readOnly: true
61 | pathType: DirectoryOrCreate
62 | - name: apiserver-log
63 | hostPath: /data0/log/apiserver
64 | mountPath: /data0/log/apiserver
65 | readOnly: false
66 | pathType: DirectoryOrCreate
67 |
68 | ---
69 | apiVersion: kubelet.config.k8s.io/v1beta1
70 | kind: KubeletConfiguration
71 | systemReserved:
72 | cpu: {{ system_reserved_cpu }}
73 | memory: {{ system_reserved_memory }}
74 | systemReservedCgroup: "systemd"
75 | cgroupDriver: "systemd"
76 |
77 | ---
78 | apiVersion: kubeproxy.config.k8s.io/v1alpha1
79 | kind: KubeProxyConfiguration
80 | mode: ipvs
--------------------------------------------------------------------------------
/roles/etcd/templates/etcd-conf.j2:
--------------------------------------------------------------------------------
1 | # This is the configuration file for the etcd server.
2 |
3 | # Human-readable name for this member.
4 | name: {{ ansible_facts.nodename }}
5 |
6 | # Path to the data directory.
7 | data-dir: {{ etcd_data_dir }}
8 |
9 | # Path to the dedicated wal directory.
10 | wal-dir: {{ etcd_data_dir }}/wal
11 |
12 | # Number of committed transactions to trigger a snapshot to disk.
13 | snapshot-count: 10000
14 |
15 | # Time (in milliseconds) of a heartbeat interval.
16 | heartbeat-interval: 100
17 |
18 | # Time (in milliseconds) for an election to timeout.
19 | election-timeout: 1000
20 |
21 | # Raise alarms when backend size exceeds the given quota. 0 means use the
22 | # default quota.
23 | quota-backend-bytes: 16589934592
24 |
25 | # List of comma separated URLs to listen on for peer traffic.
26 | listen-peer-urls: https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }}
27 |
28 | # List of comma separated URLs to listen on for client traffic.
29 | listen-client-urls: https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_port }},https://127.0.0.1:{{ etcd_listen_port }}
30 |
31 | # Maximum number of snapshot files to retain (0 is unlimited).
32 | max-snapshots: 5
33 |
34 | # Maximum number of wal files to retain (0 is unlimited).
35 | max-wals: 5
36 |
37 | max-txn-ops: 128
38 | # Comma-separated white list of origins for CORS (cross-origin resource sharing).
39 | cors:
40 |
41 | # List of this member's peer URLs to advertise to the rest of the cluster.
42 | # The URLs needed to be a comma-separated list.
43 | initial-advertise-peer-urls: https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }}
44 |
45 | # List of this member's client URLs to advertise to the public.
46 | # The URLs needed to be a comma-separated list.
47 | advertise-client-urls: https://{{ ansible_facts.default_ipv4.address }}:{{ etcd_listen_port }},https://127.0.0.1:{{ etcd_listen_port }}
48 |
49 | # Discovery URL used to bootstrap the cluster.
50 | discovery:
51 |
52 | # Valid values include 'exit', 'proxy'
53 | discovery-fallback: 'proxy'
54 |
55 | # HTTP proxy to use for traffic to discovery service.
56 | discovery-proxy:
57 |
58 | # DNS domain used to bootstrap initial cluster.
59 | discovery-srv:
60 |
61 | # Initial cluster configuration for bootstrapping.
62 | initial-cluster: {% for host in groups.etcd %}{{ hostvars[host].ansible_facts.nodename }}=https://{{ hostvars[host].ansible_facts.default_ipv4.address }}:{{ etcd_listen_peer_port }}{{ ',' if not loop.last else '\n' }}{% endfor %}
63 | # Initial cluster token for the etcd cluster during bootstrap.
64 | initial-cluster-token: '88888888'
65 |
66 | # Initial cluster state ('new' or 'existing').
67 | initial-cluster-state: new
68 |
69 | # Reject reconfiguration requests that would cause quorum loss.
70 | strict-reconfig-check: true
71 |
72 | # Accept etcd V2 client requests
73 | enable-v2: true
74 |
75 | # Enable runtime profiling data via HTTP server
76 | enable-pprof: true
77 |
78 | # Valid values include 'on', 'readonly', 'off'
79 | proxy: 'off'
80 |
81 | # Time (in milliseconds) an endpoint will be held in a failed state.
82 | proxy-failure-wait: 5000
83 |
84 | # Time (in milliseconds) of the endpoints refresh interval.
85 | proxy-refresh-interval: 30000
86 |
87 | # Time (in milliseconds) for a dial to timeout.
88 | proxy-dial-timeout: 1000
89 |
90 | # Time (in milliseconds) for a write to timeout.
91 | proxy-write-timeout: 5000
92 |
93 | # Time (in milliseconds) for a read to timeout.
94 | proxy-read-timeout: 0
95 |
96 | client-transport-security:
97 | # Path to the client server TLS cert file.
98 | cert-file: {{ etcd_cert_dir }}/server.pem
99 |
100 | # Path to the client server TLS key file.
101 | key-file: {{ etcd_cert_dir }}/server-key.pem
102 | # Enable client cert authentication.
103 | client-cert-auth: true
104 |
105 | # Path to the client server TLS trusted CA cert file.
106 | trusted-ca-file: {{ etcd_cert_dir }}/ca.pem
107 |
108 | # Client TLS using generated certificates
109 | auto-tls: false
110 |
111 | peer-transport-security:
112 | # Path to the peer server TLS cert file.
113 | cert-file: {{ etcd_cert_dir }}/peer.pem
114 |
115 | # Path to the peer server TLS key file.
116 | key-file: {{ etcd_cert_dir }}/peer-key.pem
117 |
118 | # Enable peer client cert authentication.
119 | client-cert-auth: true
120 |
121 | # Path to the peer server TLS trusted CA cert file.
122 | trusted-ca-file: {{ etcd_cert_dir }}/ca.pem
123 |
124 | # Peer TLS using generated certificates.
125 | auto-tls: false
126 |
127 | # Enable debug-level logging for etcd.
128 | debug: false
129 |
130 | logger: zap
131 |
132 | # Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
133 | log-outputs: [stderr]
134 |
135 | # Force to create a new one member cluster.
136 | force-new-cluster: false
137 | auto-compaction-mode: periodic
138 | auto-compaction-retention: 100m
139 | experimental-backend-bbolt-freelist-type: map
140 | experimental-enable-lease-checkpoint: true
141 | metrics: extensive
142 | pre-vote: true
143 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 使用方法
2 | ---
3 | 基于centos7 4.19内核利用ansible-playbook分role实现k8s集群的新建、扩容、销毁、缩容功能, etcd集群部署等. 部分资源是离线下载安装, 如kubeadm等安装包、kube镜像等, 一些是在线安装如containerd、docker等, 可自行根据环境需求修改playbook.
4 |
5 | 支持按照不同环境配置参数变量, 变量统一在group_vars目录和vars/{{env}}.yml中. 已经内置了k8s版本变量, 后续可增加不同版本的k8s部署. 支持指定网络模式安装calico或者flannel网络插件.
6 |
7 | 仅创建etcd集群: `ansible-playbook -i hosts/demo cluster-create.yml -e env=dev --tags="etcd"` or `ansible-playbook -i hosts/demo etcd-create.yml -e env=dev`
8 |
9 | 创建k8s集群(包含etcd外部集群搭建): `ansible-playbook -i hosts/demo cluster-create.yml -e env=dev`
10 |
11 | 删除k8s集群(包括删除etcd外部集群): `ansible-playbook -i hosts/demo cluster-destroy.yml`
12 |
13 | 新增节点: `ansible-playbook -i hosts/demo cluster-expanda.yml -e env=dev`
14 |
15 | 删除节点: `ansible-playbook -i hosts/demo cluster-reduce.yml`
16 |
17 | ### 目录结构
18 | ---
19 | ```bash
20 | ├── files # 全局文件
21 | ├── group_vars # group变量
22 | ├── hosts # inventory host
23 | ├── roles # role列表
24 | │ ├── common # 通用角色, 安装软件, 创建文件夹等
25 | │ │ ├── files
26 | │ │ ├── tasks
27 | │ │ └── templates
28 | │ ├── etcd # 创建etcd集群
29 | │ │ ├── files
30 | │ │ ├── handlers
31 | │ │ ├── tasks
32 | │ │ └── templates
33 | │ ├── kube-master # 创建master, 支持多master
34 | │ │ ├── files
35 | │ │ ├── tasks
36 | │ │ └── templates
37 | │ ├── kube-network # 应用网络
38 | │ │ ├── files
39 | │ │ └── tasks
40 | │ └── kube-node # 增加node
41 | │ ├── files
42 | │ ├── tasks
43 | │ └── templates
44 | └── vars # env环境变量配置
45 | ```
46 |
47 |
48 | ### 参考文档
49 | ---
50 | [kubernetes/CHANGELOG/CHANGELOG-1.24.md/dependencies](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.24.md#dependencies)
51 |
52 | [kubernetes.io](https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/install-kubeadm/)
53 |
54 | ### 离线资源下载和安装
55 | ---
56 | etcd.tar.gz下载:
57 | ```bash
58 | # 或者通过github etcd页面下载指定版本的压缩包
59 | ETCD_VER=v3.5.17
60 | wget https://github.com/etcd-io/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz
61 | cp etcd-v3.5.16-linux-amd64.tar.gz files/
62 | ```
63 |
64 |
65 |
66 | k8s相关rpm离线下载安装示例: kubeadm kubectl kubelet cri-tools kubernetes-cni. 无外网情况下通过[阿里云mirros](http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/Packages)下载下来通过createrepo命令自建仓库, 或者放入到已有自建仓库中, 或者直接通过ansible copy到目标机器rpm安装.
67 | ```bash
68 | curl http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/Packages/de422b616a367cafae90aef704625fc34b0b222353f4fb59235bb3cf2f9d0988-kubelet-1.24.0-0.x86_64.rpm -o kubelet-1.24.0-0.x86_64.rpm
69 | ...
70 | rpm -ivh kubernetes-cni-1.2.0-0.x86_64.rpm kubelet-1.24.0-0.x86_64.rpm
71 | rpm -ivh cri-tools-1.19.0-0.x86_64.rpm kubectl-1.24.0-0.x86_64.rpm
72 | rpm -ivh kubeadm-1.24.0-0.x86_64.rpm
73 | ```
74 |
75 |
76 |
77 | kubeadm相关镜像离线下载导入示例: 相关镜像可以提前下载通过docker save/load到目标master机器, 此处是k8s v1.24.0 docker版本示例
78 | ```bash
79 | # config imageRepository=registry.aliyuncs.com/google_containers, 无法访问公网的情况下提前下载并save
80 | kubeadm config print init-defaults > default-init.yml
81 | # 设置仓库地址为imageRepository: registry.aliyuncs.com/google_containers
82 | vim default-init.yml
83 | # 查看需要的镜像
84 | kubeadm config images list --config=./default-init.yml
85 | registry.aliyuncs.com/google_containers/kube-apiserver:v1.24.0
86 | registry.aliyuncs.com/google_containers/kube-controller-manager:v1.24.0
87 | registry.aliyuncs.com/google_containers/kube-scheduler:v1.24.0
88 | registry.aliyuncs.com/google_containers/kube-proxy:v1.24.0
89 | registry.aliyuncs.com/google_containers/pause:3.7
90 | registry.aliyuncs.com/google_containers/coredns:v1.8.6
91 |
92 | # images下载示例
93 | for i in registry.aliyuncs.com/google_containers/kube-apiserver:v1.24.0 registry.aliyuncs.com/google_containers/kube-controller-manager:v1.24.0 registry.aliyuncs.com/google_containers/kube-scheduler:v1.24.0 registry.aliyuncs.com/google_containers/kube-proxy:v1.24.0 registry.aliyuncs.com/google_containers/pause:3.2 registry.aliyuncs.com/google_containers/coredns:1.6.7;do docker pull $i;done
94 |
95 | # docker save load举例
96 | docker save -o kubeadm-v1.24.0.images.tar.gz registry.aliyuncs.com/google_containers/kube-apiserver:v1.27.0 registry.aliyuncs.com/google_containers/kube-controller-manager:v1.27.0 registry.aliyuncs.com/google_containers/kube-scheduler:v1.27.0 registry.aliyuncs.com/google_containers/kube-proxy:v1.27.0 registry.aliyuncs.com/google_containers/pause:3.9 registry.aliyuncs.com/google_containers/coredns:v1.10.1
97 | docker save -o infra-pause.3.7.image.tar.gz registry.aliyuncs.com/google_containers/pause:3.7
98 |
99 | docker load -i infra-pause.3.7.image.tar.gz
100 | docker load -i kubeadm-v1.24.0.images.tar.gz
101 |
102 | # containerd export import举例
103 | ctr -n k8s.io images export kubeadm-v1.24.0.images.tar.gz registry.aliyuncs.com/google_containers/coredns:v1.8.6 xxx
104 | ctr -n k8s.io image import kubeadm-v1.24.0.images.tar.gz
105 | ```
106 |
107 |
108 |
109 | flannel网络插件安装:
110 | ```bash
111 | for i in docker.io/flannel/flannel:v0.26.2 docker.io/flannel/flannel-cni-plugin:v1.6.0-flannel1 docker.io/flannel/flannel:v0.26.2;do docker pull $i; done
112 | docker save -o flannel-v0.26.2.images.tar.gz docker.io/flannel/flannel:v0.26.2 docker.io/flannel/flannel-cni-plugin:v1.6.0-flannel1 docker.io/flannel/flannel:v0.26.2
113 | wget https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
114 | # scp
115 | docker load -i flannel-v0.26.2.images.tar.gz
116 | # ctr -n k8s.io image import flannel-v0.26.2.images.tar.gz
117 | kubectl apply -f kube-flannel.yml
118 | ```
119 |
120 |
121 |
122 | calico网络插件安装:
123 | ```bash
124 | for i in calico.tar.gz docker.io/calico/cni:v3.24.1 docker.io/calico/cni:v3.24.1 docker.io/calico/node:v3.24.1 docker.io/calico/node:v3.24.1 docker.io/calico/kube-controllers:v3.24.1;do docker pull $i; done
125 | docker save -o calico-v3.24.1.images.tar.gz calico.tar.gz docker.io/calico/cni:v3.24.1 docker.io/calico/cni:v3.24.1 docker.io/calico/node:v3.24.1 docker.io/calico/node:v3.24.1 docker.io/calico/kube-controllers:v3.24.1
126 | wget wget https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/calico.yaml
127 | # scp
128 | docker load -i calico-v3.24.1.images.tar.gz
129 | # ctr -n k8s.io image import calico-v3.24.1.images.tar.gz
130 | kubectl apply -f kube-calico.yml
131 | ```
132 |
133 |
134 |
135 | [docker-public centos7 x86_64 mirrors](https://download.docker.com/linux/centos/7/x86_64/stable/Packages/): 下载docker和containerd安装略
136 |
137 |
138 |
--------------------------------------------------------------------------------
/roles/common/templates/containerd.toml.j2:
--------------------------------------------------------------------------------
1 | disabled_plugins = []
2 | imports = []
3 | oom_score = 0
4 | plugin_dir = ""
5 | required_plugins = []
6 | root = "/var/lib/containerd"
7 | state = "/run/containerd"
8 | temp = ""
9 | version = 2
10 |
11 | [cgroup]
12 | path = ""
13 |
14 | [debug]
15 | address = ""
16 | format = ""
17 | gid = 0
18 | level = ""
19 | uid = 0
20 |
21 | [grpc]
22 | address = "/run/containerd/containerd.sock"
23 | gid = 0
24 | max_recv_message_size = 16777216
25 | max_send_message_size = 16777216
26 | tcp_address = ""
27 | tcp_tls_ca = ""
28 | tcp_tls_cert = ""
29 | tcp_tls_key = ""
30 | uid = 0
31 |
32 | [metrics]
33 | address = ""
34 | grpc_histogram = false
35 |
36 | [plugins]
37 |
38 | [plugins."io.containerd.gc.v1.scheduler"]
39 | deletion_threshold = 0
40 | mutation_threshold = 100
41 | pause_threshold = 0.02
42 | schedule_delay = "0s"
43 | startup_delay = "100ms"
44 |
45 | [plugins."io.containerd.grpc.v1.cri"]
46 | device_ownership_from_security_context = false
47 | disable_apparmor = false
48 | disable_cgroup = false
49 | disable_hugetlb_controller = true
50 | disable_proc_mount = false
51 | disable_tcp_service = true
52 | enable_selinux = false
53 | enable_tls_streaming = false
54 | enable_unprivileged_icmp = false
55 | enable_unprivileged_ports = false
56 | ignore_image_defined_volumes = false
57 | max_concurrent_downloads = 3
58 | max_container_log_line_size = 16384
59 | netns_mounts_under_state_dir = false
60 | restrict_oom_score_adj = false
61 | sandbox_image = "{{ kube_image_repo }}/pause:3.7"
62 | selinux_category_range = 1024
63 | stats_collect_period = 10
64 | stream_idle_timeout = "4h0m0s"
65 | stream_server_address = "127.0.0.1"
66 | stream_server_port = "0"
67 | systemd_cgroup = false
68 | tolerate_missing_hugetlb_controller = true
69 | unset_seccomp_profile = ""
70 |
71 | [plugins."io.containerd.grpc.v1.cri".cni]
72 | bin_dir = "/opt/cni/bin"
73 | conf_dir = "/etc/cni/net.d"
74 | conf_template = ""
75 | ip_pref = ""
76 | max_conf_num = 1
77 |
78 | [plugins."io.containerd.grpc.v1.cri".containerd]
79 | default_runtime_name = "runc"
80 | disable_snapshot_annotations = true
81 | discard_unpacked_layers = false
82 | ignore_rdt_not_enabled_errors = false
83 | no_pivot = false
84 | snapshotter = "overlayfs"
85 |
86 | [plugins."io.containerd.grpc.v1.cri".containerd.default_runtime]
87 | base_runtime_spec = ""
88 | cni_conf_dir = ""
89 | cni_max_conf_num = 0
90 | container_annotations = []
91 | pod_annotations = []
92 | privileged_without_host_devices = false
93 | runtime_engine = ""
94 | runtime_path = ""
95 | runtime_root = ""
96 | runtime_type = ""
97 |
98 | [plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.options]
99 |
100 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
101 |
102 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
103 | base_runtime_spec = ""
104 | cni_conf_dir = ""
105 | cni_max_conf_num = 0
106 | container_annotations = []
107 | pod_annotations = []
108 | privileged_without_host_devices = false
109 | runtime_engine = ""
110 | runtime_path = ""
111 | runtime_root = ""
112 | runtime_type = "io.containerd.runc.v2"
113 |
114 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
115 | BinaryName = ""
116 | CriuImagePath = ""
117 | CriuPath = ""
118 | CriuWorkPath = ""
119 | IoGid = 0
120 | IoUid = 0
121 | NoNewKeyring = false
122 | NoPivotRoot = false
123 | Root = ""
124 | ShimCgroup = ""
125 | SystemdCgroup = false
126 |
127 | [plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime]
128 | base_runtime_spec = ""
129 | cni_conf_dir = ""
130 | cni_max_conf_num = 0
131 | container_annotations = []
132 | pod_annotations = []
133 | privileged_without_host_devices = false
134 | runtime_engine = ""
135 | runtime_path = ""
136 | runtime_root = ""
137 | runtime_type = ""
138 |
139 | [plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime.options]
140 |
141 | [plugins."io.containerd.grpc.v1.cri".image_decryption]
142 | key_model = "node"
143 |
144 | [plugins."io.containerd.grpc.v1.cri".registry]
145 | config_path = ""
146 |
147 | [plugins."io.containerd.grpc.v1.cri".registry.auths]
148 |
149 | [plugins."io.containerd.grpc.v1.cri".registry.configs]
150 |
151 | [plugins."io.containerd.grpc.v1.cri".registry.headers]
152 |
153 | [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
154 |
155 | [plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming]
156 | tls_cert_file = ""
157 | tls_key_file = ""
158 |
159 | [plugins."io.containerd.internal.v1.opt"]
160 | path = "/opt/containerd"
161 |
162 | [plugins."io.containerd.internal.v1.restart"]
163 | interval = "10s"
164 |
165 | [plugins."io.containerd.internal.v1.tracing"]
166 | sampling_ratio = 1.0
167 | service_name = "containerd"
168 |
169 | [plugins."io.containerd.metadata.v1.bolt"]
170 | content_sharing_policy = "shared"
171 |
172 | [plugins."io.containerd.monitor.v1.cgroups"]
173 | no_prometheus = false
174 |
175 | [plugins."io.containerd.runtime.v1.linux"]
176 | no_shim = false
177 | runtime = "runc"
178 | runtime_root = ""
179 | shim = "containerd-shim"
180 | shim_debug = false
181 |
182 | [plugins."io.containerd.runtime.v2.task"]
183 | platforms = ["linux/amd64"]
184 | sched_core = false
185 |
186 | [plugins."io.containerd.service.v1.diff-service"]
187 | default = ["walking"]
188 |
189 | [plugins."io.containerd.service.v1.tasks-service"]
190 | rdt_config_file = ""
191 |
192 | [plugins."io.containerd.snapshotter.v1.aufs"]
193 | root_path = ""
194 |
195 | [plugins."io.containerd.snapshotter.v1.btrfs"]
196 | root_path = ""
197 |
198 | [plugins."io.containerd.snapshotter.v1.devmapper"]
199 | async_remove = false
200 | base_image_size = ""
201 | discard_blocks = false
202 | fs_options = ""
203 | fs_type = ""
204 | pool_name = ""
205 | root_path = ""
206 |
207 | [plugins."io.containerd.snapshotter.v1.native"]
208 | root_path = ""
209 |
210 | [plugins."io.containerd.snapshotter.v1.overlayfs"]
211 | root_path = ""
212 | upperdir_label = false
213 |
214 | [plugins."io.containerd.snapshotter.v1.zfs"]
215 | root_path = ""
216 |
217 | [plugins."io.containerd.tracing.processor.v1.otlp"]
218 | endpoint = ""
219 | insecure = false
220 | protocol = ""
221 |
222 | [proxy_plugins]
223 |
224 | [stream_processors]
225 |
226 | [stream_processors."io.containerd.ocicrypt.decoder.v1.tar"]
227 | accepts = ["application/vnd.oci.image.layer.v1.tar+encrypted"]
228 | args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
229 | env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
230 | path = "ctd-decoder"
231 | returns = "application/vnd.oci.image.layer.v1.tar"
232 |
233 | [stream_processors."io.containerd.ocicrypt.decoder.v1.tar.gzip"]
234 | accepts = ["application/vnd.oci.image.layer.v1.tar+gzip+encrypted"]
235 | args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
236 | env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
237 | path = "ctd-decoder"
238 | returns = "application/vnd.oci.image.layer.v1.tar+gzip"
239 |
240 | [timeouts]
241 | "io.containerd.timeout.bolt.open" = "0s"
242 | "io.containerd.timeout.shim.cleanup" = "5s"
243 | "io.containerd.timeout.shim.load" = "5s"
244 | "io.containerd.timeout.shim.shutdown" = "3s"
245 | "io.containerd.timeout.task.state" = "2s"
246 |
247 | [ttrpc]
248 | address = ""
249 | gid = 0
250 | uid = 0
251 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------