使用kubeadm部署k8s(无坑版本)

系统信息

  • CentOS Linux release 7.6.1810 (Core)
  • 3.10.0-957.27.2.el7.x86_64

环境准备

  • 关闭防火墙

    $ systemctl stop firewalld
    $ systemctl disable firewalld
    
  • 关闭selinux:

    $ sed -i 's/enforcing/disabled/' /etc/selinux/config 
    $ setenforce 0
    
  • 关闭swap:

    $ echo "vm.swappiness = 0">> /etc/sysctl.conf
    $ swapoff -a
    
  • 将桥接的IPv4流量传递到iptables的链:

    $ cat > /etc/sysctl.d/k8s.conf << EOF
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF
    
  • 加载内核模块

    $ modprobe br_netfilter
    
  • 设置repo源

    $ rm -rfv /etc/yum.repos.d/*
    
    # base repo
    $ curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    
    # docker repo
    $ curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
    # k8s repo 
    $ cat > /etc/yum.repos.d/kubernetes.repo << EOF
    [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
    
    # update cache
    $ yum clean all  
    $ yum makecache  
    $ yum repolist
    
  • 安装常用包

    $ yum install vim bash-completion net-tools gcc -y
    

所有节点安装docker/kubeadm/kubelet

# 安装docker
$ yum install docker-ce-18.06.3.ce -y

# 添加阿里云仓库加速(最好换成自己的) 
$ mkdir -p /etc/docker
$ tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://ahtqbhz9.mirror.aliyuncs.com"]
}
EOF

$ systemctl daemon-reload
$ systemctl restart docker
$ systemctl enable docker

# 安装 kubeadm、kubelet、kubectl
$ yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
$ systemctl enable kubelet

部署Kubernetes Master

# apiserver-advertise-address地址就是master的IP。
$ kubeadm init --kubernetes-version=1.18.0  \
--apiserver-advertise-address=10.128.143.100   \
--image-repository registry.aliyuncs.com/google_containers  \
--service-cidr=10.10.0.0/16 --pod-network-cidr=10.122.0.0/16

$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

设置命令补全

$ source <(kubectl completion bash)

安装calico网络

$ kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

查看pod和node

$ kubectl get pod --all-namespaces
$ kubectl get node

使用单节点k8s

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

原文链接:https://how2play.club /archives/使用kubeadm部署k8s

你可能感兴趣的:(使用kubeadm部署k8s(无坑版本))