kubernetes学习-02-kubeadm工具的安装
2020-05-10 本文已影响0人
因梦伟
kubeadm安装及如下博客的内容主要参考k8s官网
1.设置kubernetes yum源
设置内核参数
As a requirement for your Linux Node’s iptables to correctly see bridged traffic, you should ensure net.bridge.bridge-nf-call-iptables is set to 1 in your sysctl config, e.g.
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
#有的安装文档安装haproxy作为负载均衡,haproxy安装在master节点,因此也添加了如下两个内核参数
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
EOF
sudo sysctl --system
官网google的yum源被墙无法安装,因此这里使用阿里云的kubernetes的yum源进行安装
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
# Set SELinux in permissive mode (effectively disabling it)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
#默认安装的是最新文档版本,可以根据自己需求安装指定版本,例如:
yum install -y kubelet-<version> kubectl-<version> kubeadm-<version>
yum install -y kubelet-1.15.1 kubeadm-1.15.1 kubectl-1.15.1
systemctl enable --now kubelet
systemctl daemon-reload
注意:如果仅仅安装kubelet/kubeadm/docker而不运行k8s的组件,
那么注释掉下面两行Environment,同时在/etc/sysconfig/kubelet文件内添加追加--cgroup-driver=systemd
最终/etc/sysconfig/kubelet文件的内容为
KUBELET_EXTRA_ARGS=--cgroup-driver=systemd
否则kubelet启动失败。如果是安装kubeadm、kubelet、docker是基于安装k8s master组件的,kubelet启动失败是由于还未进行Kubeadm init的初始化,初始化之后,两行Environment对应的文件内会生产配置信息,同时也会自动添加--cgroup-driver=systemd信息,然后kubelet启动成功。
以下是配置文件路径为/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/sysconfig/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
systemctl restart kubelet
2.kubernetes端口
2.1控制面板节点端口
Protocol | Direction | Port Rang | Purpose | Used By |
---|---|---|---|---|
TCP | Inbound | 6443* | Kubernetes API server | All |
TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd |
TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
TCP | Inbound | 10251 | kube-scheduler | Self |
TCP | Inbound | 10252 | kube-controller-manager | Self |
2.2工作节点端口
Protocol | Direction | Port Range | Purpose | Used By |
---|---|---|---|---|
TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
TCP | Inbound | 30000-32767 | NodePort Services | All |