Docker 与 K8S学习笔记(十四)—— Minikube的安装

上一篇我们简单介绍了Kubernetes基本概念,在正式进入学习之前呢我们当务之急是需要搭一套Kubernetes环境,考虑到我们仅仅是学习用所以直接使用MiniKube搭建环境。

PS:Minikube 是一个构建单节点集群的工具,是运行 Kubemetes 集群最简单、最快捷的途径

 

一、Kubectl安装

为了避免网络问题,我们直接使用阿里云的下载地址:

$ curl -Lo kubectl http://kubernetes.oss-cn-hangzhou.aliyuncs.com/kubernetes-release/release/v1.20.0/bin/linux/amd64/kubectl && chmod +x ./kubectl && sudo mv ./kubectl /usr/local/bin/kubectl

验证是否安装成功:

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38", GitTreeState:"clean", BuildDate:"2020-12-08T17:59:43Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

 

二、MiniKube安装

同样我们还是用阿里云的下载地址:

$ curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.16.0/minikube-linux-amd64 && chmod +x ./minikube && sudo mv ./minikube /usr/local/bin/minikube
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 53.7M  100 53.7M    0     0  6417k      0  0:00:08  0:00:08 --:--:-- 5776k

安装完毕后我们启动集群:

$ sudo minikube start --driver=none
😄  minikube v1.16.0 on Ubuntu 18.04
✨  Using the none driver based on user configuration

❌  Exiting due to GUEST_MISSING_CONNTRACK: Sorry, Kubernetes 1.20.0 requires conntrack to be installed in root's path

这里有报错,根据提示信息我们需要安装conntrack:

$ sudo apt-get install conntrack

再次启动,由于第一次启动,minikube会下载很多镜像,所以比较慢。启动成功后的输出如下:

$ sudo minikube start --driver=none
😄  minikube v1.16.0 on Ubuntu 18.04
✨  Using the none driver based on existing profile
👍  Starting control plane node minikube in cluster minikube
🔄  Restarting existing none bare metal machine for "minikube" ...
ℹ️  OS release is Ubuntu 18.04 LTS
🐳  Preparing Kubernetes v1.20.0 on Docker 20.10.8 ...
    ▪ kubelet.resolv-conf=/run/systemd/resolve/resolv.conf
    > kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 38.37 MiB / 38.37 MiB [---------------] 100.00% 2.68 MiB p/s 14s
    > kubeadm: 37.40 MiB / 37.40 MiB [---------------] 100.00% 2.20 MiB p/s 17s
    > kubelet: 108.69 MiB / 108.69 MiB [-------------] 100.00% 4.57 MiB p/s 24s
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🤹  Configuring local host environment ...

❗  The 'none' driver is designed for experts who need to integrate with an existing VM
💡  Most users should use the newer 'docker' driver instead, which does not require root!
📘  For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/

❗  kubectl and minikube configuration will be stored in /home/yangye
❗  To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:

    ▪ sudo mv /home/yangye/.kube /home/yangye/.minikube $HOME
    ▪ sudo chown -R $USER $HOME/.kube $HOME/.minikube

💡  This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
🔎  Verifying Kubernetes components...
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

我们可以看一下当前集群所有资源情况:

$ sudo kubectl get all -A
NAMESPACE     NAME                                READY   STATUS    RESTARTS   AGE
kube-system   pod/coredns-54d67798b7-7kshc        1/1     Running   0          100s
kube-system   pod/etcd-ayato                      1/1     Running   0          108s
kube-system   pod/kube-apiserver-ayato            1/1     Running   0          108s
kube-system   pod/kube-controller-manager-ayato   1/1     Running   0          108s
kube-system   pod/kube-proxy-cvb25                1/1     Running   0          100s
kube-system   pod/kube-scheduler-ayato            1/1     Running   0          108s
kube-system   pod/storage-provisioner             1/1     Running   0          113s

NAMESPACE     NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  117s
kube-system   service/kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   115s

NAMESPACE     NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/kube-proxy   1         1         1       1            1           kubernetes.io/os=linux   115s

NAMESPACE     NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   deployment.apps/coredns   1/1     1            1           115s

NAMESPACE     NAME                                 DESIRED   CURRENT   READY   AGE
kube-system   replicaset.apps/coredns-54d67798b7   1         1         1       100s

 

三、关于MiniKube常用命令

minikube version:查看版本

minikube status:查看状态

minikube profile list:查看属性

minikube addons list:查看当前支持的插件

minikube service list:查看服务列表

minikube node list:参看添加的node

minikube ssh:登录

minikube ip:获取IP地址

minikube start:启动或重启

minikube stop:停止

minikube delete:删除

minikube dashboard:在默认浏览器中启动仪表盘

rm-rf ~/.minikube:重置(清理所有缓存的镜像)

posted @ 2022-01-15 23:12  阿拉懒神灯  阅读(668)  评论(0编辑  收藏  举报