Mac M1 上面虚拟机 k8s v 1.19.3 小白搭建集群 命令参考

mac 系统版本

在这里插入图片描述

M1 安装虚拟机比较麻烦,只能支持centos 8 , 镜像很大, 首先要安装 虚拟机,可以参考 末尾链接,说实话,光下载 官方虚拟机百度网盘镜像 都下载了好久(暴风哭泣😭)


M1 Vmware 虚拟机 只是支持 个别的centos 镜像,其他在阿里云上面的镜像源 不可以,附上我自己网盘的链接吧 虚拟机和centos 镜像 https://pan.baidu.com/s/1V_rC-pdbdchL4zVyZFRACQ 密码: 51jq

master 节点(可以科学上网的情况下)

    3  hostnamectl --static set-hostname  k8s-master1
    4  ls
    5  hostname
    6  vi /etc/host
    7  cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-aarch64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

    8  sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
    9  sudo sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
   10  yum makecache
   11  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

   12  sysctl --system
   13  sudo yum install -y yum-utils 
   16  yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
   19  systemctl stop firewalld
   20  systemctl disable firewalld
   37  swapoff -a
   38  cp -p /etc/fstab /etc/fstab.bak$(date '+%Y%m%d%H%M%S')
   39  sed -i "s/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g" /etc/fstab
   21  vi /etc/selinux/config
   22  vi /etc/fstab
   23  sudo yum install -y yum-utils   device-mapper-persistent-data   lvm2
   24  sudo yum install -y docker-ce docker-ce-cli containerd.io
   25  sudo mkdir -p /etc/docker
   26  sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://pmp7i8xs.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
   31  sudo systemctl daemon-reload
   32  sudo systemctl enable docker
   33  sudo systemctl start docker
   34  docker -v
   35  docker ps -a
   36  sysctl -w net.bridge.bridge-nf-call-iptables=1
   40  cat /proc/sys/net/bridge/bridge-nf-call-ip6tables
   41  yum install -y kubelet-1.19.3-0 kubeadm-1.19.3-0 kubectl-1.19.3-0
   42  systemctl enable kubelet
   42  systemctl start kubelet
   43  kubelet --version
   44  kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.19.3 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.1.0.0/16
   45  curl -O https://raw.githubusercontent.com/coreos/flannel/v0.14.0/Documentation/kube-flannel.yml // 如果不能下载需要手动上传
   46  docker pull quay.io/coreos/flannel:v0.14.0
   47  kubectl apply -f kube-flannel.yml
   48  journalctl -xefu kubelet
   49  kubectl describe node k8s-master1
   50  kubectl get nodes -w
 

k8s node 节点

    1  ls
    4  hostnamectl set-hostname k8s-node2
    5  hostname
    6  ls
    7  vi /etc/host
    8  cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-aarch64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

    9  sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
   10  sudo sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
   11  yum makecache
   12  sysctl --system
   13  yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
   14  yum install -y yum-utils
   15  yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
   16  yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
   17  systemctl stop firewalld
   18  systemctl disable firewalld
   19  swapoff -a
   20  cp -p /etc/fstab /etc/fstab.bak$(date '+%Y%m%d%H%M%S')
   21  sed -i "s/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g" /etc/fstab
   22  vi /etc/selinux/config
   23  vi /etc/fstab
   24  sudo yum install -y yum-utils   device-mapper-persistent-data   lvm2
   25  sudo yum install -y docker-ce docker-ce-cli containerd.io
   26  sudo mkdir -p /etc/docker
   27  sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://pmp7i8xs.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

   28  sudo systemctl daemon-reload
   29  sudo systemctl enable docker
   30  sudo systemctl start docker
   31  docker ps -a
   32  sysctl -w net.bridge.bridge-nf-call-iptables=1
   33  yum install -y kubelet-1.19.3-0 kubeadm-1.19.3-0 kubectl-1.19.3-0
   35  systemctl enable kubelet
   36  systemctl start kubelet
   37  docker pull quay.io/coreos/flannel:v0.14.0 // 和master 的flannel 镜像保持一致,这样kubeadm join 就不用拉取镜像,加速命令执行
   37  kubeadm join 172.16.68.131:6443 --token 40t1tl.ebp3t8addacp64hv     --discovery-token-ca-cert-hash sha256:537e29bd35fda12c8411a4dccc3395dd77aa0a7d1853cfd4eb25d7e8b6b4d6ba
   41  systemctl status kubelet
   42  journalctl -xef -u kubelet -n 20
   43  history 
   44  history  > k8s-node.txt

在这里插入图片描述

希望大家都能搭建属于自己的k8s集群

具体参考

华为云arm架构安装k8s(kubernetes)
ARM架构安装Kubernetes集群
mac M1芯片安装vmware虚拟机及centos8详细教程

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐