Kubernetes安装笔记
本篇仅纯笔记,记录安装踩坑和一些细节,本次安装也仅仅只安装了3台机器,组建最小集群。
踩的小坑
- 安装时要么全局走代理,要么走国内镜像(清华源/阿里源等)
- 容器运行时的cGroupDriver一定要与kubelet的配置一致,否则kubelet起不起来,会影响集群的init
- 集群初始化生成的加入集群的token只有24小时有效期,过期需要重新生成
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
| systemctl stop firewalld.service systemctl disable firewalld.service
yum install bash-completion
sudo yum install -y yum-utils
curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli containerd.io systemctl enable docker systemctl start docker
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo \ [kubernetes] \ name=Kubernetes \ # baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch \ baseurl=https://mirrors.aliyun.com/kubernetes/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 \ gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg \ exclude=kubelet kubeadm kubectl \ EOF
sudo setenforce 0 sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet
kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers -v=7
kubeadm config print init-defaults > init-default.yml
vim init-default.yml
cat <<EOF | tee /etc/docker/daemon.json \ { \ "exec-opts": ["native.cgroupdriver=systemd"] \ } \ EOF systemctl restart docker
kubeadm init --config init-default.yml -v=7
mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
|
init-default.yml
用于集群初始化的配置文件,可以通过kubeadm config print init-defaults
得到
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
| apiVersion: kubeadm.k8s.io/v1beta3 bootstrapTokens: - groups: - system:bootstrappers:kubeadm:default-node-token token: abcdef.0123456789abcdef ttl: 24h0m0s usages: - signing - authentication kind: InitConfiguration ---
kind: KubeletConfiguration apiVersion: kubeadm.k8s.io/v1beta3 cgourpDriver: systemd --- apiServer: timeoutForControlPlane: 4m0s apiVersion: kubeadm.k8s.io/v1beta3 certificatesDir: /etc/kubernetes/pki clusterName: kubernetes controllerManager: {} dns: {} etcd: local: dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers kind: ClusterConfiguration kubernetesVersion: 1.23.0 networking: dnsDomain: cluster.local serviceSubnet: 10.96.0.0/12 scheduler: {}
|