溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

k8s如何安裝

發(fā)布時(shí)間:2021-11-16 11:06:10 來(lái)源:億速云 閱讀:158 作者:小新 欄目:云計(jì)算

這篇文章將為大家詳細(xì)講解有關(guān)k8s如何安裝,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

允許 iptables 檢查橋接流量 https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/ https://askubuntu.com/questions/783017/bash-proc-sys-net-ipv4-ip-forward-permission-denied

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

sudo yum install bridge-utils  -y
sudo echo br_netfilter > /etc/modules-load.d/br_netfilter.conf

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

sudo sysctl --system

安裝 runtime https://kubernetes.io/zh/docs/setup/production-environment/container-runtimes/

cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# 設(shè)置必需的 sysctl 參數(shù),這些參數(shù)在重新啟動(dòng)后仍然存在。
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

# Apply sysctl params without reboot
sudo sysctl --system

sudo apt-get update && sudo apt-get install -y containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo systemctl restart containerd

【ubuntu】安裝 kubeadm、kubelet 和 kubectl https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

sudo systemctl daemon-reload
sudo systemctl restart kubelet

【centos】安裝 kubeadm、kubelet 和 kubectl

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

# 將 SELinux 設(shè)置為 permissive 模式(相當(dāng)于將其禁用)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable --now kubelet

關(guān)閉swap https://stackoverflow.com/questions/47094861/error-while-executing-and-initializing-kubeadm

sudo swapoff -a

安裝etcd https://etcd.io/docs/current/dl-build/

git clone https://github.com/etcd-io/etcd.git
cd etcd
yum install golang
./build.sh
ln -s /root/etcd/bin/etcd /usr/local/bin/etcd

初始化控制平面節(jié)點(diǎn) https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/

kubeadm init --pod-network-cidr 10.244.0.0/16

export KUBECONFIG=/etc/kubernetes/admin.conf

安裝 Pod 網(wǎng)絡(luò)附加組件 https://stackoverflow.com/questions/49112336/container-runtime-network-not-ready-cni-config-uninitialized https://www.jianshu.com/p/9819a9f5dda0

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml

cat <<EOF | sudo tee /run/flannel/subnet.env
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.0.1/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true
EOF

控制平面節(jié)點(diǎn)隔離 https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/

kubectl taint nodes --all node-role.kubernetes.io/master-

發(fā)布應(yīng)用 https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/deploy-app/deploy-interactive/ https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/expose/expose-interactive/

kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080

關(guān)于“k8s如何安裝”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

k8s
AI