k8s快速安装

一、准备centos7环境,可上互联网,以下为基础配置,每一台均执行

ssh-keygen -t rsa
ssh-copy-id 主机名
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
sed -i 's/.*swap.*/#&/' /etc/fstab 
swapoff -a 
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node1
cat >> /etc/hosts <<EOF
192.168.2.8 k8s-master
192.168.2.59 k8s-node1
192.168.2.86 k8s-node2
192.168.2.8 apiserver.demo
EOF

二、安装kubelet,每台执行

export REGISTRY_MIRROR=https://registry.cn-hangzhou.aliyuncs.com
curl -sSL https://kuboard.cn/install-script/v1.19.x/install\_kubelet.sh | sh -s 1.19.5

三、其中一个master节点执行集群初始化

export MASTER_IP=192.168.2.8
export APISERVER_NAME=apiserver.demo
export POD_SUBNET=10.100.0.1/16
curl -sSL https://kuboard.cn/install-script/v1.19.x/init\_master.sh | sh -s 1.19.5
此命令会返回其他节点加入到集群的命令

四、其他master节点加入集群

kubeadm join apiserver.demo:6443 --token bphtmu.cplm6qphq73p19hd     --discovery-token-ca-cert-hash sha256:194450249fabbbadc5119c99df4d444dba8a9f750751e19af2d144c820fb2363     --control-plane --certificate-key 0881e00971310ff7f2205c0ced5c87578287f5a86d3da64a7009b092b5cf7c2a

五、其他node节点加入集群

kubeadm join apiserver.demo:6443 --token bphtmu.cplm6qphq73p19hd     --discovery-token-ca-cert-hash sha256:194450249fabbbadc5119c99df4d444dba8a9f750751e19af2d144c820fb2363  

六、检查安装情况

#查看集群设置
kubectl get cm kubeadm-config -n kube-system -o=jsonpath="{.data.ClusterConfiguration}"

#查看node
kubectl  get nodes
kubectl  get nodes -o wide

#查看pod
kubectl  get pod 
kubectl  get pod -A
kubectl  get pod  -n kube-system -o wide

七、根据情况开关可调度到master

允许调度到k8s-master
kubectl taint node k8s-master node-role.kubernetes.io/master-

禁止调度到k8s-master
kubectl taint node k8s-master node-role.kubernetes.io/master="":NoSchedule

八、测试创建容器

kubectl run net-test1 --image=alpine sleep 360000
kubectl  get pod -o wide
kubectl exec -it net-test1 sh
ping 10.100.36.65
ping www.baidu.com

九、k8s命令自动补齐

yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
posted @   小糊涂90  阅读(86)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示