type
Post
status
Published
date
Jul 25, 2022
slug
kind
summary
使用kind搭建三节点的环境
tags
Docker
K8s
category
云原生
icon
fab fa-docker
password
Property
Jul 25, 2022 07:34 AM
安装精简化集群kind
 

1. 安装阿里云repo,kubectl源

 
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo cat <<EOF > /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 EOF
 
 

2. 安装docker

yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli -y
 

3. docker配置

 
mkdir -p /etc/docker # docker的数据目录,根据需要自行修改 mkdir -p /DATA/docker cat > /etc/docker/daemon.json <<EOF { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "default-address-pools": [ { "base": "10.101.13.0/16", "size": 24 } ], "bip": "10.101.13.254/24", "storage-opts": [ "overlay2.override_kernel_check=true" ], "insecure-registries": [ "docker.nexus.com:10010" ], "registry-mirrors" : [ "https://ot2k4d59.mirror.aliyuncs.com/" ], "data-root": "/DATA/docker" } EOF
 

4. 启动docker,开机自启

systemctl start docker systemctl enable docker
 

5. 安装kubectl

 
yum install -y kubectl-1.20.15 --disableexcludes=kubernetes
 

6. 安装kind

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64 curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.12.0/kind-linux-arm64 chmod +x ./kind mv ./kind /user/local/bin/kind
 

7. 初始化kindyaml

 
注意需要将apiServerAddress对应的ip修改为自身的机器的ip
# this config file contains all config fields with comments # NOTE: this is not a particularly useful config file kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 networking: # WARNING: It is _strongly_ recommended that you keep this the default # (127.0.0.1) for security reasons. However it is possible to change this. apiServerAddress: "172.17.22.22" # By default the API server listens on a random open port. # You may choose a specific port but probably don't need to in most cases. # Using a random port makes it easier to spin up multiple clusters. apiServerPort: 6443 # patch the generated kubeadm config with some extra settings kubeadmConfigPatches: - | apiVersion: kubelet.config.k8s.io/v1beta1 kind: KubeletConfiguration evictionHard: nodefs.available: "0%" # patch it further using a JSON 6902 patch kubeadmConfigPatchesJSON6902: - group: kubeadm.k8s.io version: v1beta2 kind: ClusterConfiguration patch: | - op: add path: /apiServer/certSANs/- value: my-hostname # 1 control plane node and 3 workers nodes: # the control plane node config - role: control-plane image: kindest/node:v1.20.15 - role: worker image: kindest/node:v1.20.15 - role: worker image: kindest/node:v1.20.15 - role: worker image: kindest/node:v1.20.15
 

8. 初始化kind集群

 
kind create cluster --config kind.yaml
 
 
k8s最佳实践(一)Cni插件Flannel需要重启pod才能跨节点访问