运维开发网

centos7安装k8s 1.19

运维开发网 https://www.qedev.com 2020-10-08 09:40 出处:51CTO 作者:757781091
centos7安装k8s 1.19

主机

  192.168.254.10  k8s-master
  192.168.254.20  k8s-node1
  192.168.254.21  k8s-node2

参数配置

所有节点都要执行

  • 关闭swap

    swapoff -a
    # 注释掉/etc/fstab文件swap的行
  • 修改内核模块

    配置k8s.conf文件(#k8s.conf文件原来不存在,需要自己创建的)

    所有节点上都要做

    cat <<EOF>> /etc/sysctl.d/k8s.conf       
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1    
    vm.swappiness=0
    EOF
    sysctl --system
  • 关闭防火墙

    所有节点上都要做

    systemctl stop firewalld
    systemctl disable firewalld
  • 关闭seLinux
    1. 临时 setenforce 0
    2. 永久关闭
    vim /etc/sysconfig/seLinux
    SELinux=enforcing
    替换为
    SELinux=disabled

    准备仓库

  • k8s.repo
    cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    [kubernetes]
    name=Kubernetes
    baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    EOF
  • dockr.repo
    wget -O /etc/yum.repos.d/docker-ce.repo  https://mirrors.aliyun.com/docker-ce/Linux/centos/docker-ce.repo

安装kubeadm

三个节点上执行,实际搭建中使用的是最新的docker-ce

yum install kubeadm

systemctl enable docker
systemctl start docker

systemctl enable kubelet
# master上不安装kubelet,不能完成init

docker 配置

三个节点都要执行

将docker-ce的cgroup驱动改为systemd

cat <<EOF>> /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

配置kubelet

在多网卡的情况需要设置kubelet的ip

所节点都要配置,其它两个节点上将192.168.254.10替换为相应的ip

cat <<EOF>> /etc/sysconfig/kubelet 
KUBELET_EXTRA_ARGS=--node-ip=192.168.254.10
EOF

配置lvs

所有节点上都要做

cat <<EOF>> /etc/modules-load.d/lvs.conf
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack_ipv4
EOF

安装master

  • 查看需要的images
    
    # kubeadm  config  images list

kubeadm config images list \

--image-repository registry.aliyuncs.com/google_containers

* 生成配置文件
```bash
kubeadm  config  print init-defaults >kubeadmin-config.yml
  • 编辑配置文件
    cat kubeadmin-config.yml
    ...
    localAPIEndpoint:
    advertiseAddress: 192.168.254.10
    bindPort: 6443
    ...
    imageRepository: registry.aliyuncs.com/google_containers
    ...
    kubernetesVersion: v1.19.2
    networking:
    dnsDomain: cluster.local
    podSubnet: 10.244.0.0/16
    serviceSubnet: 10.96.0.0/12
    scheduler: {}
    ---
    apiVersion: kubeproxy.config.k8s.io/v1alpha1
    kind: KubeProxyConfiguration
    mode: "ipvs"
  • 安装master
    kubeadm init --config kubeadmin-config.yml --upload-certs   | tee kubeadmin-init.log

    也可以使用下面的命令安装

    kubeadm init --kubernetes-version=1.19.2 \
    --apiserver-advertise-address=192.168.254.10 \
    --image-repository registry.aliyuncs.com/google_containers \
    --service-cidr=10.64.0.0/24 \
    --pod-network-cidr=10.244.0.0/24
  • kubectl get cs命令报错解决

    编辑/etc/kubernetes/manifests/kube-scheduler.yaml

    /etc/kubernetes/manifests/kube-controller-manager.yaml

    # - --port=0

    然后重启kubelet

    service kubelet restart

    安装node

kubeadm join 192.168.254.10:6443 --token 1ijhgv.xgkkjhz2xu1lsm48 \
    --discovery-token-ca-cert-hash sha256:55c9fd837cc2419e57045d16d52097dda4438347d35ef961bab845dda3782288 

安装网络

不安装各node会noready,kube-flannel.yml可以下载后apply,可以在任何节点执行,执行中每个节点都会去pull image

ubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号