• K8s


    1 - minikube

    Minikube是Kubernetes的一个版本,由Kubernetes开源社区开发,专为本地部署而设计,是一种可以让你在本地轻松运行 Kubernetes 的工具。
    Minikube使用VM来创建本地单节点Kubernetes安装,因此需先确保安装了类似VirtualBox、Hyper-V或KVM等VM平台。
    通过Minikube可以在笔记本电脑上的集群中运行单节点 Kubernetes 集群, 供那些希望尝试 Kubernetes 或进行日常开发的用户使用。
    但Minikube只能局限于包含一个节点的本地集群,因此对于生产级别的多节点Kubernetes集群来说,很难在本地进行模拟测试。

    Minikube 支持以下 Kubernetes 功能:

    • DNS
    • NodePorts
    • ConfigMaps 和 Secrets
    • Dashboards
    • 容器运行时: Docker、CRI-O 以及 containerd
    • 启用 CNI (容器网络接口)
    • Ingress
    • 安装

    2 - 环境准备

    已安装docker

    [anliven@anliven ~]$ uname -a
    Linux anliven 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
    [anliven@anliven ~]$
    [anliven@anliven ~]$ cat /etc/system-release
    CentOS Linux release 7.8.2003 (Core)
    [anliven@anliven ~]$
    [anliven@anliven ~]$ docker version
    Client: Docker Engine - Community
     Version:           19.03.11
     API version:       1.40
     Go version:        go1.13.10
     Git commit:        42e35e61f3
     Built:             Mon Jun  1 09:13:48 2020
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          19.03.11
      API version:      1.40 (minimum version 1.12)
      Go version:       go1.13.10
      Git commit:       42e35e61f3
      Built:            Mon Jun  1 09:12:26 2020
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.2.13
      GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
     runc:
      Version:          1.0.0-rc10
      GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
     docker-init:
      Version:          0.18.0
      GitCommit:        fec3683
    [anliven@anliven ~]$
    

    3 - 用户权限设置

    [root@anliven ~]# visudo
    [root@anliven ~]# 
    [root@anliven ~]# cat /etc/sudoers |grep anliven
    anliven    ALL=(ALL)        NOPASSWD: ALL
    [root@anliven ~]#
    [root@anliven ~]# exit
    [anliven@anliven ~]# sudo usermod -aG docker $USER && newgrp docker
    

    4 - 安装kubectl

    使用 kubectl 与集群进行交互。

    命令

    curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
    chmod +x kubectl
    sudo mv ./kubectl /usr/local/bin/kubectl
    kubectl version --client
    

    示例

    [anliven@anliven K8s]$ pwd
    /home/anliven/K8s
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 41.0M  100 41.0M    0     0  2819k      0  0:00:14  0:00:14 --:--:-- 2832k
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ chmod +x kubectl
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ sudo mv ./kubectl /usr/local/bin/kubectl
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ ls -l /usr/local/bin/kubectl
    -rwxrwxr-x 1 anliven anliven 43003904 Oct 14 22:43 /usr/local/bin/kubectl
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ kubectl version --client
    Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
    [anliven@anliven K8s]$
    

    kubectl命令帮助

    kubectl -h    # 查看子命令列表
    kubectl options    # 查看全局选项
    
    
    Use "kubectl <command> --help" for more information about a given command.
    kubectl <command> --help    # 查看子命令的帮助
    
    Use "kubectl options" for a list of global command-line options (applies to all commands).
    kubectl [command] [PARAMS] -o=<format>    # 设置输出格式(如 json、yaml、jsonpath 等)
    
    
    kubectl explain RESOURCE [options]    # 查看资源的定义
    kubectl explain -h
    
    kubectl get [flags] [options]    # 显示一个或多个资源
    kubectl get -h
    

    5 - 安装minikube

    命令

    curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
    sudo install minikube-linux-amd64 /usr/local/bin/minikube
    minikube version
    

    示例

    [anliven@anliven K8s]$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 56.0M  100 56.0M    0     0  2510k      0  0:00:22  0:00:22 --:--:-- 2234k
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ sudo install minikube-linux-amd64 /usr/local/bin/minikube
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ ls -l /usr/local/bin/minikube
    -rwxr-xr-x 1 root root 58733392 Oct 14 22:46 /usr/local/bin/minikube
    [anliven@anliven K8s]$
    [anliven@anliven K8s]$ minikube version
    minikube version: v1.14.0
    commit: b09ee50ec047410326a85435f4d99026f9c4f5c4
    

    6 - 从github下载并安装kubectl和minikube

    如果无法访问google站点,也可以从github下载并安装kubectl和minikube。

    kubectl

    1. 访问 https://github.com/kubernetes/kubernetes/releases
    2. 点击类似CHANGELOG-*.*.md的链接,在“Client Binaries”区域找到匹配的二进制包,
    3. 下载并解压,然后放入/usr/local/bin目录

    minikube

    找到匹配的二进制包并下载: https://github.com/kubernetes/minikube/releases/

    curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v1.14.0/minikube-linux-arm64
    chmod +x minikube
    sudo mv minikube /usr/local/bin
    

    也可以使用阿里云的minikube地址: https://github.com/AliyunContainerService/minikube

    curl -Lo minikube https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.13.0/minikube-linux-amd64
    chmod +x minikube
    sudo mv minikube /usr/local/bin/
    

    7 - 启动与运行minikube

    示例

    [anliven@anliven ~]$ minikube start
    * minikube v1.14.0 on Centos 7.8.2003 (vbox/amd64)
    * Automatically selected the docker driver
    * Starting control plane node minikube in cluster minikube
    * Pulling base image ...        # 第一次会拉取基础镜像,用时较久
    * Creating docker container (CPUs=2, Memory=2200MB) ...
    * Preparing Kubernetes v1.19.2 on Docker 19.03.8 ...
        > kubelet.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
        > kubeadm.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
        > kubectl.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
        > kubeadm: 37.30 MiB / 37.30 MiB [-------------] 100.00% 822.08 KiB p/s 47s
        > kubectl: 41.01 MiB / 41.01 MiB [-------------] 100.00% 881.98 KiB p/s 48s
        > kubelet: 104.88 MiB / 104.88 MiB [------------] 100.00% 1.58 MiB p/s 1m6s
    * Verifying Kubernetes components...
    * Enabled addons: storage-provisioner, default-storageclass
    * Done! kubectl is now configured to use "minikube" by default
    [anliven@anliven ~]$
    [anliven@anliven ~]$ docker images |grep k8s
    gcr.io/k8s-minikube/kicbase                                         v0.0.13             90f1294ff9ac        2 weeks ago         800MB
    [anliven@anliven ~]$
    [anliven@anliven ~]$ docker ps
    CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                                                                                                      NAMES
    5d520392622e        gcr.io/k8s-minikube/kicbase:v0.0.13   "/usr/local/bin/entr…"   4 hours ago         Up 4 hours          127.0.0.1:32775->22/tcp, 127.0.0.1:32774->2376/tcp, 127.0.0.1:32773->5000/tcp, 127.0.0.1:32772->8443/tcp   minikube
    [anliven@anliven ~]$
    

    启动参数说明

    --driver    从1.5.0版本开始,Minikube缺省使用本地最好的驱动来创建Kubernetes本地环境
    --image-mirror-country cn    将缺省利用 registry.cn-hangzhou.aliyuncs.com/google_containers 作为安装Kubernetes的容器镜像仓库
    --iso-url    指定镜像地址下载相应的 .iso 文件
    --registry-mirror    为了拉取Docker Hub镜像,需要为 Docker daemon 配置镜像加速
    --cpus=2    为minikube虚拟机分配CPU核数
    --memory=2048mb    为minikube虚拟机分配内存数
    --kubernetes-version    minikube 虚拟机将使用的 kubernetes 版本
    

    8 - Minikube 命令

    命令帮助

    Use "minikube <command> --help" for more information about a given command.
    Use "minikube options" for a list of global command-line options (applies to all commands).
    

    命令选项

    [anliven@anliven ~]$ minikube options
    The following options can be passed to any command:
    
          --alsologtostderr=false: log to standard error as well as files
      -b, --bootstrapper='kubeadm': The name of the cluster bootstrapper that will set up the Kubernetes cluster.
          --log_backtrace_at=:0: when logging hits line file:N, emit a stack trace
          --log_dir='': If non-empty, write log files in this directory
          --logtostderr=false: log to standard error instead of files
      -p, --profile='minikube': The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently.
          --stderrthreshold=2: logs at or above this threshold go to stderr
      -v, --v=0: log level for V logs
          --vmodule=: comma-separated list of pattern=N settings for file-filtered logging
    [anliven@anliven ~]$
    

    一些命令

    Minikube 集群

    minikube version    # 查看版本
    
    minikube status    # 查看状态
    minikube profile list  # 查看属性
    minikube addons list    # 查看当前支持的插件
    minikube service list   # 查看服务列表
    minikube node list    # 参看添加的node
    
    minikube ssh    # 登录集群
    
    minikube start    # 启动集群
    minikube stop    # 停止集群
    minikube delete    # 删除集群
    
    minikube dashboard    # 启动Dashboard
    
    rm-rf ~/.minikube    #  重置(清理所有缓存的镜像,重头开始)
    

    一些示例

    [anliven@anliven ~]$ minikube status    # 查看集群状态
    minikube
    type: Control Plane
    host: Running
    kubelet: Running
    apiserver: Running
    kubeconfig: Configured
    
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube profile list    # 查看集群属性
    |----------|-----------|---------|--------------|------|---------|---------|
    | Profile  | VM Driver | Runtime |      IP      | Port | Version | Status  |
    |----------|-----------|---------|--------------|------|---------|---------|
    | minikube | docker    | docker  | 192.168.49.2 | 8443 | v1.19.2 | Running |
    |----------|-----------|---------|--------------|------|---------|---------|
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube addons list    # 查看集群当前支持的插件
    |-----------------------------|----------|--------------|
    |         ADDON NAME          | PROFILE  |    STATUS    |
    |-----------------------------|----------|--------------|
    | ambassador                  | minikube | disabled     |
    | csi-hostpath-driver         | minikube | disabled     |
    | dashboard                   | minikube | enabled ✅   |
    | default-storageclass        | minikube | enabled ✅   |
    | efk                         | minikube | disabled     |
    | freshpod                    | minikube | disabled     |
    | gcp-auth                    | minikube | disabled     |
    | gvisor                      | minikube | disabled     |
    | helm-tiller                 | minikube | disabled     |
    | ingress                     | minikube | disabled     |
    | ingress-dns                 | minikube | disabled     |
    | istio                       | minikube | disabled     |
    | istio-provisioner           | minikube | disabled     |
    | kubevirt                    | minikube | disabled     |
    | logviewer                   | minikube | disabled     |
    | metallb                     | minikube | disabled     |
    | metrics-server              | minikube | disabled     |
    | nvidia-driver-installer     | minikube | disabled     |
    | nvidia-gpu-device-plugin    | minikube | disabled     |
    | olm                         | minikube | disabled     |
    | pod-security-policy         | minikube | disabled     |
    | registry                    | minikube | disabled     |
    | registry-aliases            | minikube | disabled     |
    | registry-creds              | minikube | disabled     |
    | storage-provisioner         | minikube | enabled ✅   |
    | storage-provisioner-gluster | minikube | disabled     |
    | volumesnapshots             | minikube | disabled     |
    |-----------------------------|----------|--------------|
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube service list    # 查看集群服务列表
    |----------------------|---------------------------|--------------|-----|
    |      NAMESPACE       |           NAME            | TARGET PORT  | URL |
    |----------------------|---------------------------|--------------|-----|
    | default              | kubernetes                | No node port |
    | kube-system          | kube-dns                  | No node port |
    | kubernetes-dashboard | dashboard-metrics-scraper | No node port |
    | kubernetes-dashboard | kubernetes-dashboard      | No node port |
    |----------------------|---------------------------|--------------|-----|
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube ssh    # 登录集群
    docker@minikube:~$ whoami
    docker
    docker@minikube:~$ exit
    logout
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube stop    # 停止集群
    * Stopping node "minikube"  ...
    * Powering off "minikube" via SSH ...
    * 1 nodes stopped.
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube status    # 查看集群状态
    minikube
    type: Control Plane
    host: Stopped
    kubelet: Stopped
    apiserver: Stopped
    kubeconfig: Stopped
    
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube start        # 重新启动,不会“Pulling base image ...”
    * minikube v1.14.0 on Centos 7.8.2003 (vbox/amd64)
    * Using the docker driver based on existing profile
    * Starting control plane node minikube in cluster minikube
    * Restarting existing docker container for "minikube" ...
    * Preparing Kubernetes v1.19.2 on Docker 19.03.8 ...
    * Verifying Kubernetes components...
    * Enabled addons: default-storageclass, storage-provisioner, dashboard
    * Done! kubectl is now configured to use "minikube" by default
    [anliven@anliven ~]$
    [anliven@anliven ~]$ minikube status    # 查看集群状态
    minikube
    type: Control Plane
    host: Running
    kubelet: Running
    apiserver: Running
    kubeconfig: Configured
    
    [anliven@anliven ~]$ 
    

    启动Dashboard

    9 - 问题处理

    1 - minikube启动失败

    [root@anliven K8s]# minikube start
    * minikube v1.14.0 on Centos 7.8.2003 (vbox/amd64)
    * Automatically selected the docker driver
    * The "docker" driver should not be used with root privileges.
    * If you are running minikube within a VM, consider using --driver=none:
    *   https://minikube.sigs.k8s.io/docs/reference/drivers/none/
    
    X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
    

    处理方法: 使用非root用户,并将此用户添加到docker组: sudo usermod -aG docker $USER && newgrp docker

    2 - dashboard启动失败

    [anliven@anliven ~]$ minikube dashboard
    * Enabling dashboard ...
    * Verifying dashboard health ...
    * Launching proxy ...
    * Verifying proxy health ...
    * Opening http://127.0.0.1:37006/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
    START /usr/bin/firefox "http://127.0.0.1:37006/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/"
    Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
    Running without a11y support!
    Error: no DISPLAY environment variable specified
    xdg-open: no method available for opening 'http://127.0.0.1:37006/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/'
    
    X Exiting due to HOST_BROWSER: failed to open browser: exit status 3
    
    [anliven@anliven ~]$ 
    

    处理方法: 需要图形界面下的命令行中执行minikube dashboard,以便启动浏览器

    10 - 参考信息

  • 相关阅读:
    linux python2.6升级2.7
    Kafka介绍及安装部署
    kafka搭建
    Zookeeper 集群的安装及高可用性验证已完成!
    grafana初体验
    mac 密码重置
    制作 macOS High Sierra U盘
    运维监控篇Zabbix简单的性能调优
    zabbix主动模式设置
    OpenCV入门:(六:基础画图函数)
  • 原文地址:https://www.cnblogs.com/anliven/p/13844135.html
Copyright © 2020-2023  润新知