安装K8S

1.安装K8S集群

1.1 配置需求

硬件:

主机操作系统CUPMEM角色要求
k8s-masterubuntu22Gmaster
k8s-node1ubuntu22Gworker
k8s-node2ubuntu22Gworker

1.2 设置主机名

hostnamectl set-hostname xxx
三台主机名:
master1 192.168.216.100 
worker1 192.168.216.101 
worker2 192.168.216.102

1.3 主机IP地址

ip a s

1.4 安装ssh工具

apt-get update
apt-get install openssh-server

1.5 安装docker

apt-get install docker.io

查看docker版本

docker version

1.6 下载k8s

apt-get update && apt-get install -y apt-transport-https curl
apt-get install -y kubelet kubeadm kubectl --allow-unauthenticated

直接运行这个指令下载会报错,需要换源

echo deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main | sudo tee /etc/apt/sources.list.d/kubernetes.list

换源刷新apt

apt update

如果报错The following signatures couldn’t be verified because the public key is not available

则执行下面命令,为其添加 key。

curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add 

然后再安装k8s,这里最新的版本是1.21.1,但是它需要的镜像国内源没有更新,所以安装旧的版本

	apt-get install -y   kubectl=1.18.5-00    --allow-downgrades  --allow-unauthenticated
	apt-get install kubernetes-cni=0.8.6-00
	
	apt-get install -y kubelet=1.18.5-00 kubeadm=1.18.5-00 kubectl=1.18.5-00

这时候执行以下指令看看有没有安装

kubectl version

会提示

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.5", GitCommit:"e6503f8d8f769ace2f338794c914a96fc335df0f", GitTreeState:"clean", BuildDate:"2020-06-26T03:47:41Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?

1.7 配置环境

打开hosts⽂件 (根据自己的ip配置)

vim /etc/hosts
192.168.236.177 master
192.168.236.178 node1
192.168.236.179 node2

关闭swap

sudo swapoff -a

k8s初始化

kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.18.5

成功会显示,记住最后一条,这个是用来加入结点的

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.5.138:6443 --token 33tg59.293qc9carbgtaw94 \
    --discovery-token-ca-cert-hash sha256:6a0bc72e1c9c57866b2a0dec94226c70d4bd40474d944b60398b5135dd2bb976

根据提示执行

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

安装fannel

查看k8s结点状态

kubectl get nodes
NAME         STATUS     ROLES    AGE   VERSION
k8s-master   NotReady   master   58m   v1.18.5

可以发现结点没有运行起来,这里需要安装fannel

先在http://ip.tool.chinaz.com/找到域名对应的ip地址,查找raw.githubusercontent.com的ip

然后进入到hosts添加

vi /etc/hosts

把下面这行加入到里面

61.175.228.187 raw.githubusercontent.com

然后再执行安装fannel的指令

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

再次查看结点情况就会运行起来了(可能需要等几分钟)

NAME         STATUS   ROLES    AGE   VERSION
k8s-master   Ready    master   63m   v1.18.5

一些错误

出现以下错误时

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

使用以下指令删除lock

sudo rm /var/lib/dpkg/lock-frontend       
sudo rm /var/lib/dpkg/lock

kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=NumCPU

如果要修改k8s的版本,可以执行下面这个指令删除

apt-get remove -y kubelet kubeadm kubectl
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值