镜像下载、域名解析、时间同步请点击阿里云开源镜像站
在本文中,我们将了解如何在 Ubuntu 20.04 上安装 Kubernetes。在过去的几年里,容器化为开发人员提供了很大的灵活性。最常用的容器化应用程序之一是 Docker。
运行小型应用程序并不困难,但如果您想要扩展它们该怎么办?当您有数百台服务器时,扩展起来就不那么容易了。应该有一个自动化工具,完全负责将资源分配给我们在特定机器上的应用程序,不仅如此,而且还要持续监控和灵活性。
[En]
It’s not difficult to run small applications, but what if you want to extend them? When you have hundreds of servers, it’s not so easy to scale. There should be an automated tool that is fully responsible for allocating resources to our applications on specific machines, not only that, but also continuous monitoring and flexibility.
在容器上部署服务的主要原因之一是它们灵活、轻量级并且在部署在数百台机器上时易于扩展。但是,谁来管理所有这些容器?这就是 Kubernetes 发挥作用的地方。
什么是 Kubernetes?
Kubernetes(也称为”K8s”)是 Google 的一个开源项目,用于通过提供扩展、部署和维护等服务来管理集群上的容器化应用程序。
Kubernetes 目前是市场领导者,在大多数场景中击败了 Docker Swarm 和 Apache Mesos 等竞争对手。然而,Kubernetes 的一大缺点是设置困难。一些云供应商确实提供了预制集群供您使用,但它们是付费的。当您只想免费学习 Kubernetes 时该怎么办?
让我们看看如何在 Ubuntu 20.04 上运行 Kubernetes 集群。
Kubernetes 安装——使用 kubeadm
首先,有两个虚拟机设置。我们将其中一个用作主节点,另一个用作工作节点。
[En]
First, there are two virtual machine settings. We use one of them as our master node and the other as the work node.
安装 Docker
linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt update
linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt install docker.io
启动Docker
linuxmi@linuxmi:~/www.linuxmi.com$ sudo systemctl start docker
查看状态
linuxmi@linuxmi:~/www.linuxmi.com$ systemctl status docker.service
设置开机启动
linuxmi@linuxmi:~/www.linuxmi.com$ sudo systemctl enable docker
查看 Docker 版本
linuxmi@linuxmi:~/www.linuxmi.com$ docker version
禁用交换内存
暂时禁止:
linuxmi@linuxmi:~/www.linuxmi.com$ sudo swapoff -a
永久禁止:
linuxmi@linuxmi:~/www.linuxmi.com$ sudo nano /etc/fstab
在此文件中,注释掉该 /swapfile 行。
设置主机名
linuxmi@linuxmi:~/www.linuxmi.com$ sudo hostnamectl set-hostname kubernetes-master
linuxmi@linuxmi:~/www.linuxmi.com$ sudo hostnamectl set-hostname kubernetes-worker
安装 Kubernetes
sudo apt-get install -y ca-certificates curl software-properties-common apt-transport-https curl
linuxmi@linuxmi:~/www.linuxmi.com$ curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
OK
linuxmi@linuxmi:~/www.linuxmi.com$ sudo tee /etc/apt/sources.list.d/kubernetes.list < deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
> EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt-get update
linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt-get install -y kubelet kubeadm kubectl
linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt-mark hold kubelet kubeadm kubectl
kubelet 设置为保留。
kubeadm 设置为保留。
kubectl 设置为保留。
初始化 Kubernetes 主服务器
在主节点上运行这些:
kubernetes-master:~$ sudo kubeadm init
kubernetes-master:~$ mkdir -p $HOME/.kube
kubernetes-master:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
kubernetes-master:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
部署 Pod 网络
kubernetes-master:~$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubernetes-master:~$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
kubernetes-master:~$ kubectl get pods --all-namespaces
加入 Kubernetes 集群
从工作节点运行这些:
kubernetes-worker:~$ sudo kubeadm join 192.168.1.220:6443 --token 1exb8s.2t4k3b5syfc3jfmo --discovery-token-ca-cert-hash sha256:72ad481cee4918cf2314738419356c9a402fb609263adad48c13797d0cba2341
kubernetes-master:~$ kubectl get nodes
Kubernetes 安装 – 使用 minikube(本地)
对于这个演示,我们将使用一个名为minikube的应用程序。使用 Ctrl + Alt + T 打开终端并输入以下 命令:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start
这将在本地启动一个 Kubernetes 集群。要停止集群,您可以:
要访问本地 Kubernetes 的仪表板:
minikube dashboard
OK,就这样
本文转自:https://blog.51cto.com/u_13510521/5167724
Original: https://www.cnblogs.com/helong-123/p/16107375.html
Author: 萌褚
Title: 在Ubuntu20.04上安装Kubernetes-Kubeadm和Minikube
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/523874/
转载文章受原作者版权保护。转载请注明原作者出处!