k8s安装

作者: simon_kin | 来源:发表于2021-07-26 10:39 被阅读0次

    平台 :CentOS Linux release 7.5.1804 (Core)
    master: 192.168.253.150
    node1: 192.168.253.151
    node2: 192.168.253.152

    准备工作

    配置ip

    cd /etc/sysconfig/network-scripts

    GATEWAY="192.168.253.2"
    NETMASK="255.255.255.0"
    IPADDR="192.168.253.150"
    DNS1=223.5.5.5
    DNS2=223.6.6.6

    开通ssh

    vi /etc/ssh/sshd_config
    systemctl start sshd

    关闭防火墙

    systemctl stop firewalld
    systemctl disable firewalld

    关闭selinux

    查看selinux状态:/usr/sbin/sestatus -v
    vi /etc/sysconfig/selinux
    SELINUX=enforcing

    master安装部署

    • 使用yum安装etcd和kubernetes-master
      yum install etcd kubernetes-master -y
    • 编辑/etc/etcd/etcd.conf文件

    ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
    ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
    ETCD_NAME="default"
    ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"

    • 编辑/etc/kubernetes/apiserver文件

    KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
    KUBE_API_PORT="--port=8080"
    KUBELET_PORT="--kubelet-port=10250"
    KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
    KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
    KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
    KUBE_API_ARGS=""

    • 启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服务,并设置开机启动。

    for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl start $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done

    • 在etcd中定义flannel网络

    etcdctl mk /atomic.io/network/config '{"Network":"172.40.0.0/16"}'

    node安装部署

    node节点安装都一样

    • 使用yum安装flannel和kubernetes-node
      yum install flannel kubernetes-node -y
    • 为flannel网络指定etcd服务,修改/etc/sysconfig/flanneld文件

    vi /etc/sysconfig/flanneld
    FLANNEL_ETCD_ENDPOINTS="http://masterip:2379"
    FLANNEL_ETCD_PREFIX="/atomic.io/network"

    • 修改/etc/kubernetes/config文件

    vi /etc/kubernetes/config
    KUBE_LOGTOSTDERR="--logtostderr=true"
    KUBE_LOG_LEVEL="--v=0"
    KUBE_ALLOW_PRIV="--allow-privileged=false"
    KUBE_MASTER="--master=http://masterip:8080"

    • 修改node节点配置文件/etc/kubernetes/kubelet

    vi /etc/kubernetes/kubelet
    KUBELET_ADDRESS="--address=0.0.0.0"
    KUBELET_PORT="--port=10250"
    KUBELET_HOSTNAME="--hostname-override=nodeip"
    KUBELET_API_SERVER="--api-servers=http://masterip:8080"
    KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
    KUBELET_ARGS=""

    • 配置完node后,在所有Node节点上启动flanneld,docker,kube-proxy,kubelet服务,并设置开机启动。这里强调一下,一定要注意etcd—->flannel—–>docker的先后启动顺序,否则会导致pod里边的ip会和其他node节点的pod不在一个网段,通信就有问题。

    for SERVICES in flanneld docker kube-proxy kubelet;do systemctl start $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done
    至此,node配置完毕。

    三,验证集群状态
    1,验证集群是否安装成功。 master执行如下命令:

    kubectl get node
    NAME STATUS AGE
    192.168.253.51 Ready 3m
    192.168.253.52 Ready 3m
    2,查看网络情况

    etcdctl ls -r | grep subnets
    /atomic.io/network/subnets
    /atomic.io/network/subnets/172.40.7.0-24
    /atomic.io/network/subnets/172.40.3.0-24
    [root@kube-master-01 ~]# etcdctl get /atomic.io/network/subnets/172.40.7.0-24
    {"PublicIP":"192.168.253.51"}
    [root@kube-master-01 ~]# etcdctl get /atomic.io/network/subnets/172.40.3.0-24
    {"PublicIP":"192.168.253.52"}

    相关文章

      网友评论

          本文标题:k8s安装

          本文链接:https://www.haomeiwen.com/subject/yhwwmltx.html