k8s安装配置
Posted 我是廖志伟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s安装配置相关的知识,希望对你有一定的参考价值。
文章目录
命令脚本
各个节点设置
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
sed -ri 's/.*swap.*/#&/' /etc/fstab
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
vim /etc/hosts
192.168.160.130 k8s-master
192.168.160.131 k8s-node1
192.168.160.132 k8s-node2
master节点设置
cat >> /etc/hosts << EOF
192.168.160.130 k8s-master
192.168.160.131 k8s-node1
192.168.160.132 k8s-node2
EOF
各个节点设置
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables =1
net.bridge.bridge-nf-call-iptables =1
EOF
sysctl --system
ntpdate time.nist.gov
ntpdate ntp.aliyun.com
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum list docker-ce --showduplicates | sort -r
yum install -y yum-utils
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce-17.12.1.ce
systemctl start docker
systemctl enable docker.service
systemctl list-unit-files | grep docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
"registry-mirrors": ["https://jdxszd2m.mirror.aliyuncs.com"]
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl status docker
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=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum update -y
yum install kubelet-1.19.9-0 kubeadm-1.19.9-0 kubectl-1.19.9-0 -y
systemctl enable kubelet
systemctl start kubelet
export KUBECONFIG=/etc/kubernetes/kubelet.conf
source /etc/profile
master节点安装
kubeadm init \\
--apiserver-advertise-address=0.0.0.0 \\
--image-repository registry.aliyuncs.com/google_containers \\
--kubernetes-version v1.19.9 \\
--service-cidr=10.96.0.0/12 \\
--pod-network-cidr=10.244.0.0/16
一般网速比较快的也要等个一二分钟的样子,才行。
安装失败后需要重新执行,此时要先执行
kubeadm reset
master节点
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
sudo kubectl apply -f kube-flannel.yml
非master节点执行
kubeadm join 192.168.11.24:6443 --token u8c2u9.tym99mgthqr9f9au \\
--discovery-token-ca-cert-hash sha256:3d9e965e96f4714687d6e1289d1764e150937c8881bd07304ad265ece5452c31
各个节点都执行
sudo kubeadm token create --print-join-command --ttl=0
查看节点情况
kubectl get nodes
三个k8s节点都已经准备就绪
安装nginx
kubectl create deployment nginx ‐‐image=nginx
kubectl expose deployment nginx ‐‐port=80 ‐‐type=NodePort
kubectl get pod,svc ‐o wide
总结
提示:以上就是今天要讲的内容,本文仅仅简单介绍了k8s安装配置。
以上是关于k8s安装配置的主要内容,如果未能解决你的问题,请参考以下文章
kubernetes系列03—kubeadm安装部署K8S集群
CentOS 8 二进制 高可用 安装 k8s 1.16.x