前言
准备环境
安装 ansible 配置免密
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| yum -y install sshpass ansible git
for i in 1.1.1.1 1.1.1.107 1.1.1.246 1.1.1.151 1.1.1.32;do sshpass -p asdf3.14 ssh-copy-id -o StrictHostKeyChecking=no root@${i};done
for i in 1.1.1.1 1.1.1.107 1.1.1.246 1.1.1.151 1.1.1.32;do echo ${i} >> /etc/ansible/hosts;done
$ yum -y install net-tools
$ cat <<E0F > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg E0F
$
$ yum install -y kubeadm-1.17.0-0 kubelet-1.17.0-0 kubectl-1.17.0-0
$ sed -i "s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
$ systemctl enable kubelet && systemctl start kubelet
|
配置yum源
vim kubernetes.repo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
[kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
|
1
| ansible all -m copy -a 'src=./kubernetes.repo dest=/etc/yum.repos.d/ mode=0644'
|
初始化节点
下载项目
1 2
| git clone https://gitee.com/momom1/ansible_install_kubernetes.git cd ansible_install_kubernetes
|
替换 cluster.yaml 内容
1 2 3 4 5 6
| - name: init node hosts: all roles: - role: init_node - role: container tags: [ init ]
|
- 执行
1
| ansible-playbook cluster.yaml
|
安装 kubeadm
查看可以安装的版本
1 2 3 4 5 6 7
| yum list kubeadm --showduplicates | sort -r kubeadm.x86_64 1.6.0-0 kubernetes kubeadm.x86_64 1.20.2-0 kubernetes kubeadm.x86_64 1.20.1-0 kubernetes kubeadm.x86_64 1.20.0-0 kubernetes kubeadm.x86_64 1.19.7-0 kubernetes kubeadm.x86_64 1.19.6-0 kubernetes
|
安装指定版本
1 2 3 4 5
| ansible all -m shell -a "yum install -y kubeadm-1.19.7-0 kubelet-1.19.7-0 kubectl-1.19.7-0 --disableexcludes=kubernetes"
ansible all -m shell -a "systemctl enable --now kubelet"
|
使用kubeadm创建集群
使用下方内容
config.yaml
注意修改的是controlPlaneEndpoint, networking, clusterDNS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| apiServer: timeoutForControlPlane: 4m0s apiVersion: kubeadm.k8s.io/v1beta2 certificatesDir: /etc/kubernetes/pki clusterName: kubernetes controllerManager: extraArgs: bind-address: 0.0.0.0 dns: type: CoreDNS etcd: local: dataDir: /var/lib/etcd imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers kind: ClusterConfiguration kubernetesVersion: v1.19.7 controlPlaneEndpoint: "10.10.66.172:8443" networking: dnsDomain: cluster.local serviceSubnet: 10.254.0.0/16 PodSubnet: 172.30.0.0/16 scheduler: extraArgs: bind-address: 0.0.0.0 --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 bindAddress: 0.0.0.0 bindAddressHardFail: false clientConnection: acceptContentTypes: "" burst: 0 contentType: "" kubeconfig: /var/lib/kube-proxy/kubeconfig.conf qps: 0 clusterCIDR: "172.30.0.0/16" configSyncPeriod: 0s conntrack: maxPerCore: null min: null tcpCloseWaitTimeout: null tcpEstablishedTimeout: null detectLocalMode: "" enableProfiling: false healthzBindAddress: "" hostnameOverride: "" iptables: masqueradeAll: false masqueradeBit: null minSyncPeriod: 0s syncPeriod: 0s ipvs: excludeCIDRs: null minSyncPeriod: 0s scheduler: "" strictARP: false syncPeriod: 0s tcpFinTimeout: 0s tcpTimeout: 0s udpTimeout: 0s kind: KubeProxyConfiguration metricsBindAddress: "" mode: "ipvs" nodePortAddresses: null oomScoreAdj: null portRange: "" showHiddenMetricsForVersion: "" udpIdleTimeout: 0s winkernel: enableDSR: false networkName: "" sourceVip: "" --- apiVersion: kubelet.config.k8s.io/v1beta1 authentication: anonymous: enabled: false webhook: cacheTTL: 0s enabled: true x509: clientCAFile: /etc/kubernetes/pki/ca.crt authorization: mode: Webhook webhook: cacheAuthorizedTTL: 0s cacheUnauthorizedTTL: 0s cgroupDriver: systemd clusterDNS: - 10.254.0.10 clusterDomain: cluster.local cpuManagerReconcilePeriod: 0s evictionPressureTransitionPeriod: 0s fileCheckFrequency: 0s healthzBindAddress: 127.0.0.1 healthzPort: 10248 httpCheckFrequency: 0s imageMinimumGCAge: 0s kind: KubeletConfiguration logging: {} nodeStatusReportFrequency: 0s nodeStatusUpdateFrequency: 0s rotateCertificates: true runtimeRequestTimeout: 0s staticPodPath: /etc/kubernetes/manifests streamingConnectionIdleTimeout: 0s syncFrequency: 0s volumeStatsAggPeriod: 0s
|
根据输出将其他节点加入集群
参考链接: calico
1 2 3 4 5 6
| curl https: 修改变量注释: CALICO_IPV4POOL_CIDR 设置成你所选的Pod CIDR相同的值
kubectl apply -f calico.yyaml
|