K8S 环境安装
安装0 准备三台安装好docker的机器并配置hosts 如果需要手动指定固定ip 可以nmtui 打开界面设置ip (镜像:CentOS-8.4.2105-x86_64)1
安装
0 准备三台安装好docker的机器并配置hosts 如果需要手动指定固定ip 可以nmtui 打开界面设置ip (镜像:CentOS-8.4.2105-x86_64)
192.168.9.132 k8s-mastern192.168.9.133 k8s-node1n192.168.9.134 k8s-node2
1 关闭防火墙
systemctl stop firewalld nsystemctl disable firewalld
- 关闭Swap
swapoff -a # 临时关闭 nvim /etc/fstab # 永久关闭n#注释掉swap这行n# /dev/mapper/centos‐swap swap swap defaults 0 0n# 或者nsed -i 's/.*swap.*/#&/' /etc/fstab
- 关闭selinux
sed ‐i 's/enforcing/disabled/' /etc/selinux/config # 永久关闭nsetenforce 0 # 临时关闭nnsed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinuxnsed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/confignsed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinuxnsed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
- 吧桥接的ipv4流量转到iptables
cat > /etc/sysctl.d/k8s.conf << EOFn> net.bridge.bridge‐nf‐call‐ip6tables = 1n> net.bridge.bridge‐nf‐call‐iptables = 1n> EOFnn#执行使命令生效:nmodprobe br_netfilternsysctl -p /etc/sysctl.d/k8s.conf
- 添加k8s配置源
cat /etc/yum.repos.d/kubernetes.repo n[kubernetes]nname=Kubernetesnbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/nenabled=1ngpgcheck=0nrepo_gpgcheck=0ngpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg <https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg>
- 查看可以安装的k8s版本
yum list kubelet --showduplicates | sort -r
- 安装kubelet,kubeadm,kubectl
yum install -y kubelet-1.20.8-0 kubeadm-1.20.8-0 kubectl-1.20.8-0
- 设置开机启动
systemctl enable kubeletnsystemctl start kubelet
9 master节点初始化
kubeadm init --image-repository=registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.9.135 --kubernetes-version=v1.20.8 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16n# 192.168.9.135 设置成当前主机IP
10 .安装网络插件
kubectl apply ‐f <https://docs.projectcalico.org/manifests/calico.yaml>n# 如果上面这个calico网络插件安装不成功可以试下下面这个 n# kubectl apply ‐f <https://raw.githubusercontent.com/coreos/flannel/mast> er/Documentation/kubeflannel.yml
11.检测安装情况
[root@localhost kubernetes]# kubectl get pods -AnNAMESPACE NAME READY STATUS RESTARTS AGEnkube-system calico-kube-controllers-85c867d48-5c6pr 0/1 Pending 0 35snkube-system calico-node-6tjlk 0/1 Init:2/3 0 36snkube-system coredns-7f89b7bc75-rbxwv 0/1 Pending 0 5m58snkube-system coredns-7f89b7bc75-v2nvs 0/1 Pending 0 5m58snkube-system etcd-k8s-node4 1/1 Running 0 6m4snkube-system kube-apiserver-k8s-node4 1/1 Running 0 6m4snkube-system kube-controller-manager-k8s-node4 1/1 Running 0 6m4snkube-system kube-proxy-h8bcn 1/1 Running 0 5m58snkube-system kube-scheduler-k8s-node4 1/1 Running 0 6m4s
12 .如果执行显示Unhealthy
修改/etc/kubernetes/manifests 下,
vim kube-controller-manager.yaml vim kube-scheduler.yaml
将port=0注掉
执行结果
快捷键支持:
https://kubernetes.io/zh/docs/tasks/tools/included/optional-kubectl-configs-bash-linux/
yum install bash-completionnsource /usr/share/bash-completion/bash_completionnkubectl completion bash >/etc/bash_completion.d/kubectlnecho 'alias k=kubectl' >>~/.bashrcnecho 'complete -F __start_kubectl k' >>~/.bashrcnsource ~/.bashrcnn则可以执行 k get cs n[root@localhost manifests]# k get csnWarning: v1 ComponentStatus is deprecated in v1.19+nNAME STATUS MESSAGE ERRORncontroller-manager Healthy ok nscheduler Healthy ok netcd-0 Healthy {"health":"true"}