k8s环境安装

时间:2021-09-15
本文章向大家介绍k8s环境安装,主要包括k8s环境安装使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
https://blog.csdn.net/xmtblog/article/details/108806423
1.安装docker

2.环境条件

# 安装必备工具
yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 同步时间
ntpdate ntp1.aliyun.com

# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld && setenforce 0

# 禁用交换分区
swapoff -a

# 修改内核参数
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system


3.master节点安装kubeadm、kubelet、kubectl
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum安装程序时,提示xxx.rpm公钥尚未安装,使用 yum install -y xxx --nogpgcheck 命令格式跳过公钥检查:
yum install -y kubectl-1.16.0-0 kubeadm-1.16.0-0 kubelet-1.16.0-0 --nogpgcheck

systemctl start kubelet && systemctl enable kubelet

kubeadm init \
--apiserver-advertise-address=192.168.138.138 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.16.0 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16 \
--token-ttl 0

# 复制并执行以下命令
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config


# node加入集群命令
kubeadm join 192.168.138.138:6443 --token 04g6be.ssud1tiil1n5dn5u \
    --discovery-token-ca-cert-hash sha256:03802e674b57dba3adbe7d95b24353fd5b23b70cb6997be860ddebc65cac053d

# 获取node加入集群命令
kubeadm token create --print-join-command

4.node节点安装kubeadm、kubelet
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubeadm-1.16.0-0 kubelet-1.16.0-0 --nogpgcheck

systemctl start kubelet && systemctl enable kubelet

sysctl -w net.ipv4.ip_forward=1

# 加入集群
kubeadm join 192.168.138.138:6443 --token 04g6be.ssud1tiil1n5dn5u \
    --discovery-token-ca-cert-hash sha256:03802e674b57dba3adbe7d95b24353fd5b23b70cb6997be860ddebc65cac053d

# master节点安装flannel
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml

  

原文地址:https://www.cnblogs.com/konglingxi/p/15272519.html