kubernetes 修炼手册书籍整理:
kubernetes安装方式
1、测试用练习环境
2、托管的kubernetes
3、自定义安装。
1、测试用练习环境
Magic Sandbox平台
Play with Kubernetes 平台(https://labs.play-with-k8s.com/)
kubeadm reset:清理之前的集群配置。这个命令会移除网络配置并恢复主机到初始状态。
初始化操作
kubeadm init –kubernetes-version=1.19.3 –apiserver-advertise-address=192.168.137.128 –image-repository registry.aliyuncs.com/google_containers –service-cidr=10.1.0.0/16 –pod-network-cidr=10.244.0.0/16
初始化后出现以下界面即表示成功。
报错
解决方法:禁用 Swap
临时禁用
sudo swapoff -a
永久禁用
/dev/mapper/your-swap-partition none swap sw 0 0
报错
关闭之后启动kubelet
systemctl start kubelet
解决方法:更改主机名
hostnamectl set-hostname node1
加入集群
[root@master ~]# kubeadm join 192.168.72.123:6443 --token oindpm.wprzpeacsxlznslb --discovery-token-ca-cert-hash sha256:9a9a59592a5bd5a819ef5008ecc37681b7e7a4c6857171b6ab112e4221efd8ac [preflight] Running pre-flight checks [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/ [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml' [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Starting the kubelet [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap... This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details. Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
出现上面的kubectl get nodes 即表示加入成功
如果出现下面错误:
[root@bogon kubeblog]# kubectl get nodes
The connection to the server localhost:8080 was refused – did you specify the right host or port?
则需要执行下面代码
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
问题:
集群节点重启后导致节点NotReady状态且kubelet无法启动
解决方法:关闭swap(这种问题是由于之前是手动关闭的但是没有在/etc/fstab文件中关闭swap)
swapoff -a 关闭swap
在/etc/fstab文件中注释掉swap相关配置
慕课网整理:
部署目标
在所有节点上安装Docker和kubeadm,kubelet
部署容器网络插件flannel
安装基础软件
1、配置Master和work节点的域名
2、CPU设置为2核
3、下载阿里云的yum源repo文件
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
4、安装基础软件包
yum install wget net-tools ntp git ‐y
5、同步系统时间
ntpdate 0.asia.pool.ntp.org
6、配置docker、k8s的yum源
7、确保br_netfilter模块被加载
8、将桥接的IPv4流量传递到iptables