Last active
February 18, 2025 07:06
-
-
Save yankay/a863cf2e300bff6f9040ab1c6c58fbae to your computer and use it in GitHub Desktop.
快速 启动一套 kubespray 集群(Ubuntu)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 安装 kubespray | |
cd /opt | |
git clone https://github.com/kubernetes-sigs/kubespray.git | |
cd kubespray | |
pip3 install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com | |
# 配置集群 | |
# Copy ``inventory/sample`` as ``inventory/mycluster`` | |
cp -rfp inventory/sample inventory/mycluster | |
# Update Ansible inventory file with inventory builder | |
declare -a IPS=(10.10.1.3 10.10.1.4 10.10.1.5) | |
CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]} | |
# 编辑 inventory/mycluster/hosts.yaml 文件 | |
# 使用自定义配置 | |
rm -rf /opt/kubespray/inventory/mycluster/group_vars | |
mkdir -p /opt/kubespray/inventory/mycluster/group_vars/all | |
curl https://gist.githubusercontent.com/yankay/a863cf2e300bff6f9040ab1c6c58fbae/raw/ab96867375325c6f43dc1e00ddd4f3d60e472487/customize.yml > /opt/kubespray/inventory/mycluster/group_vars/all/customize.yml | |
mkdir -p /opt/kubespray/inventory/my/group_vars/k8s_cluster | |
curl https://gist.githubusercontent.com/yankay/a863cf2e300bff6f9040ab1c6c58fbae/raw/ab96867375325c6f43dc1e00ddd4f3d60e472487/k8s-customize.yml > /opt/kubespray/inventory/mycluster/group_vars/all/k8s-customize.yml | |
# 运行 | |
cd /opt/kubespray/ | |
export ANSIBLE_CONFIG=/opt/kubespray/ansible.cfg | |
ansible-playbook -i inventory/mycluster/hosts.yaml --become --become-user=root cluster.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Normal | |
# Download Config | |
download_run_once: true | |
download_container: false | |
download_localhost: true | |
# skip_downloads: true | |
# http_proxy: "socks5://10.6.108.200:10808" | |
# gcr and kubernetes image repo define | |
gcr_image_repo: "gcr.m.daocloud.io" | |
kube_image_repo: "k8s.m.daocloud.io" | |
# docker image repo define | |
docker_image_repo: "docker.m.daocloud.io" | |
# quay image repo define | |
quay_image_repo: "quay.m.daocloud.io" | |
# github image repo define (ex multus only use that) | |
github_image_repo: "ghcr.m.daocloud.io" | |
files_repo: "https://files.m.daocloud.io" | |
## Kubernetes components | |
kubeadm_download_url: "{{ files_repo }}/dl.k8s.io/release/{{ kubeadm_version }}/bin/linux/{{ image_arch }}/kubeadm" | |
kubectl_download_url: "{{ files_repo }}/dl.k8s.io/release/{{ kube_version }}/bin/linux/{{ image_arch }}/kubectl" | |
kubelet_download_url: "{{ files_repo }}/dl.k8s.io/release/{{ kube_version }}/bin/linux/{{ image_arch }}/kubelet" | |
## CNI Plugins | |
cni_download_url: "{{ files_repo }}/github.com/containernetworking/plugins/releases/download/{{ cni_version }}/cni-plugins-linux-{{ image_arch }}-{{ cni_version }}.tgz" | |
## cri-tools | |
crictl_download_url: "{{ files_repo }}/github.com/kubernetes-sigs/cri-tools/releases/download/{{ crictl_version }}/crictl-{{ crictl_version }}-{{ ansible_system | lower }}-{{ image_arch }}.tar.gz" | |
## [Optional] etcd: only if you **DON'T** use etcd_deployment=host | |
etcd_download_url: "{{ files_repo }}/github.com/etcd-io/etcd/releases/download/{{ etcd_version }}/etcd-{{ etcd_version }}-linux-{{ image_arch }}.tar.gz" | |
# [Optional] Calico: If using Calico network plugin | |
calicoctl_download_url: "{{ files_repo }}/github.com/projectcalico/calico/releases/download/{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}" | |
calicoctl_alternate_download_url: "{{ files_repo }}/github.com/projectcalico/calicoctl/releases/download/{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}" | |
# [Optional] Calico with kdd: If using Calico network plugin with kdd datastore | |
calico_crds_download_url: "{{ files_repo }}/github.com/projectcalico/calico/archive/{{ calico_version }}.tar.gz" | |
# [Optional] Flannel: If using Falnnel network plugin | |
flannel_cni_download_url: "{{ files_repo }}/kubernetes/flannel/{{ flannel_cni_version }}/flannel-{{ image_arch }}" | |
# [Optional] helm: only if you set helm_enabled: true | |
helm_download_url: "{{ files_repo }}/get.helm.sh/helm-{{ helm_version }}-linux-{{ image_arch }}.tar.gz" | |
# [Optional] crun: only if you set crun_enabled: true | |
crun_download_url: "{{ files_repo }}/github.com/containers/crun/releases/download/{{ crun_version }}/crun-{{ crun_version }}-linux-{{ image_arch }}" | |
# [Optional] kata: only if you set kata_containers_enabled: true | |
kata_containers_download_url: "{{ files_repo }}/github.com/kata-containers/kata-containers/releases/download/{{ kata_containers_version }}/kata-static-{{ kata_containers_version }}-{{ ansible_architecture }}.tar.xz" | |
# [Optional] cri-dockerd: only if you set container_manager: docker | |
cri_dockerd_download_url: "{{ files_repo }}/github.com/Mirantis/cri-dockerd/releases/download/v{{ cri_dockerd_version }}/cri-dockerd-{{ cri_dockerd_version }}.{{ image_arch }}.tgz" | |
# [Optional] runc,containerd: only if you set container_runtime: containerd | |
runc_download_url: "{{ files_repo }}/github.com/opencontainers/runc/releases/download/{{ runc_version }}/runc.{{ image_arch }}" | |
containerd_download_url: "{{ files_repo }}/github.com/containerd/containerd/releases/download/v{{ containerd_version }}/containerd-{{ containerd_version }}-linux-{{ image_arch }}.tar.gz" | |
nerdctl_download_url: "{{ files_repo }}/github.com/containerd/nerdctl/releases/download/v{{ nerdctl_version }}/nerdctl-{{ nerdctl_version }}-{{ ansible_system | lower }}-{{ image_arch }}.tar.gz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kube_proxy_mode: iptables | |
enable_nodelocaldns: false | |
etcd_deployment_type: kubeadm | |
ntp_enabled: true | |
calico_feature_detect_override: "ChecksumOffloadBroken=true" #Fix Issue for Calico #4727 | |
# metrics_server_enabled: true | |
#local_path_provisioner_enabled: true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment