k8s安装
程序员文章站
2024-03-11 16:18:55
...
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
禁用Selinux
apt install selinux-utils
setenforce 0
禁用swap
swapoff -a
同时把/etc/fstab包含swap那行记录删掉。
用阿里云安装:
sudo apt-get update && apt-get install -y apt-transport-https curl
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
> deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
> EOF
apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
重启:
systemctl daemon-reload
systemctl restart kubelet
kubeadm init --apiserver-advertise-address=192.168.122.37 --pod-network-cidr=192.168.0.0/16
sudo docker pull mirrorgooglecontainers/kube-apiserver:v1.13.4
sudo docker pull mirrorgooglecontainers/kube-controller-manager:v1.13.4
sudo docker pull mirrorgooglecontainers/kube-scheduler:v1.13.4
sudo docker pull mirrorgooglecontainers/pause:3.1
sudo docker pull mirrorgooglecontainers/kube-proxy:v1.13.4
sudo docker pull mirrorgooglecontainers/etcd:3.2.24
sudo docker pull coredns/coredns:1.2.6
sudo docker tag mirrorgooglecontainers/kube-apiserver:v1.13.4 k8s.gcr.io/kube-apiserver:v1.13.4
sudo docker tag mirrorgooglecontainers/kube-controller-manager:v1.13.4 k8s.gcr.io/kube-controller-manager:v1.13.4
sudo docker tag mirrorgooglecontainers/kube-scheduler:v1.13.4 k8s.gcr.io/kube-scheduler:v1.13.4
sudo docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
sudo docker tag mirrorgooglecontainers/kube-proxy:v1.13.4 k8s.gcr.io/kube-proxy:v1.13.4
sudo docker tag mirrorgooglecontainers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
sudo docker tag coredns/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6
kubeadm join 192.168.122.60:6443 --token 4pk6qb.jajs4rzjsckwaafw --discovery-token-ca-cert-hash sha256:1bd7057e6211da749c5a554f538b7362d1a53a2a4fefd41f68fbf526a0f1e5da
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
安装pod网络:
calico:
--pod-network-cidr=192.168.0.0/16
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml
flannel:
--pod-network-cidr=10.244.0.0/16
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
获取所有namespace下的pod:
kubectl get pods --all-namespaces
获取kubelet日志:
journalctl -f -u kubelet
master节点获取集群信息:
kubectl get nodes
master节点删除node节点:
kubectl drain name --delete-local-data --force --ignore-daemonsets
kubectl delete node name
获取pods:
kubectl get pods