美文网首页Just programing
Kubernetes 学习笔记 001

Kubernetes 学习笔记 001

作者: chengchaos | 来源:发表于2020-02-13 17:43 被阅读0次

    Kubernetes

    Kubernates 的概念

    Namespace

    Kubernetes 使用 namespace 来划分成多个虚拟集群,用以供不同的团队或业务群组使用,进行资源隔离等。

    创建新 namespace 的命令:

    kubectl create namespace chengchaos
    

    Pod

    Pod 是 kubernetes 的最小调度单元,可以看作应用服务的逻辑宿主机,通常可以这样理解:部署几个实例,就是部署几个 Pod。

    Replication Controller

    Pod 的控制器,用于监控指定条件 Pod 的实例状态,并维持其健康个数为指定的副本数量。其主要功能包括:确保 Pod实例数量、确保 Pod 健康、弹性伸缩、滚动升级。

    Service

    Service 为一组提供相同服务的 Pod 提供对外访问,具备对 Pod 的服务返现、路由的能力。

    Label

    Label 用来关联 Pod 和 Service,每个 Pod 可以定义 Label,然后 Service 可以通过 Label 去选择服务哪些 Pod。

    Deployment

    Repllication Controller 的升级版,对 Deployment 进行了更新、展示及控制,可以查看升级的纤细进度及状态,对每次 Deployment 进行版本管理,方便回滚,也可以对升级行为进行暂停和继续等。

    Minikube

    Minikube 是 Kubernetes 提供的

    文档地址:

    https://kubernetes.io/docs/tasks/tools/install-minikube/

    安装 Minikube

    1. 安装 Docker

    参考: https://docs.docker.com/install/linux/docker-ce/centos/

    $ sudo yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine
    $ sudo yum install -y yum-utils \
      device-mapper-persistent-data \
      lvm2
    $ sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
    $ sudo yum install docker-ce docker-ce-cli containerd.io
    $ sudo systemctl start docker
    $ sudo docker run hello-world
    
    1. 安装 kubectl

    参考: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-linux

    $ 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
    Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:14:22Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
    
    1. 安装 Minikube

    参考: https://kubernetes.io/docs/tasks/tools/install-minikube/

    $ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
      && chmod +x minikube
    $ sudo mkdir -p /usr/local/bin/
    $ sudo install minikube /usr/local/bin/
    
    $ minikube status
    E0213 16:27:33.329391   10179 status.go:98] The "minikube" cluster does not exist!
    host: Nonexistent
    kubelet: Nonexistent
    apiserver: Nonexistent
    kubeconfig: Nonexistent
    
    1. 安装 VirtualBox
    $ sudo -i
    # cd /etc/yum.repos.d/
    # touch virtualbox.repo
    # vim virtualbox.repo
    

    virtualbox.repo 内容如下:

    [virtualbox]
    name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
    baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
    

    安装 VirtualBox :

    #  written                            
    [root@bogon yum.repos.d]# yum search VirtualBox
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.zju.edu.cn
     * extras: mirror.lzu.edu.cn
     * updates: mirrors.zju.edu.cn
    virtualbox/7/x86_64/signature                            |  181 B     00:00     
    Retrieving key from https://www.virtualbox.org/download/oracle_vbox.asc
    Importing GPG key 0x98AB5139:
     Userid     : "Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>"
     Fingerprint: 7b0f ab3a 13b9 0743 5925 d9c9 5442 2a4b 98ab 5139
     From       : https://www.virtualbox.org/download/oracle_vbox.asc
    Is this ok [y/N]: y
    virtualbox/7/x86_64/signature                            | 2.9 kB     00:04 !!! 
    virtualbox/7/x86_64/primary_db                             | 146 kB   00:01     
    =========================== N/S matched: VirtualBox ============================
    VirtualBox-4.3.x86_64 : Oracle VM VirtualBox
    VirtualBox-5.0.x86_64 : Oracle VM VirtualBox
    VirtualBox-5.1.x86_64 : Oracle VM VirtualBox
    VirtualBox-5.2.x86_64 : Oracle VM VirtualBox
    VirtualBox-6.0.x86_64 : Oracle VM VirtualBox
    VirtualBox-6.1.x86_64 : Oracle VM VirtualBox
    
      Name and summary matches only, use "search all" for everything.
    # yum -y install VirtualBox-6.1
    # exit
    
    1. 启动 Minikube
    $ minikube start --vm-driver=virtualbox
    * minikube v1.7.2 on Centos 7.7.1908
    * Using the virtualbox driver based on user configuration
    * Downloading VM boot image ...
    
    $
    * minikube v1.7.2 on Centos 7.7.1908
    * Using the virtualbox driver based on user configuration
    * Creating virtualbox VM (CPUs=2, Memory=2000MB, Disk=20000MB) ...
    * 
    X Unable to start VM. Please investigate and run 'minikube delete' if possible
    * Error: [VBOX_DRV_NOT_LOADED] create: precreate: We support Virtualbox starting with version 5. Your VirtualBox install is "WARNING: The vboxdrv kernel module is not loaded. Either there is no module\n         available for the current kernel (3.10.0-1062.9.1.el7.x86_64) or it failed to\n         load. Please recompile the kernel module and install it by\n\n           sudo /sbin/vboxconfig\n\n         You will not be able to start VMs until this problem is fixed.\n5.1.38r122592". Please upgrade at https://www.virtualbox.org
    * Suggestion: Reinstall VirtualBox and reboot. Alternatively, try the kvm2 driver: https://minikube.sigs.k8s.io/docs/reference/drivers/kvm2/
    * Related issues:
      - https://github.com/kubernetes/minikube/issues/4043
      - https://github.com/kubernetes/minikube/issues/4711
    $ sudo /sbin/vboxconfig 
    vboxdrv.sh: Stopping VirtualBox services.
    vboxdrv.sh: Building VirtualBox kernel modules.
    This system is not currently set up to build kernel modules (system extensions).
    Running the following commands should set the system up correctly:
    
      yum install gcc make
      yum install kernel-devel-3.10.0-1062.9.1.el7.x86_64
    (The last command may fail if your system is not fully updated.)
      yum install kernel-devel
    vboxdrv.sh: failed: Look at /var/log/vbox-install.log to find out what went wrong.
    This system is not currently set up to build kernel modules (system extensions).
    Running the following commands should set the system up correctly:
    
      yum install gcc make
      yum install kernel-devel-3.10.0-1062.9.1.el7.x86_64
    (The last command may fail if your system is not fully updated.)
      yum install kernel-devel
    
    There were problems setting up VirtualBox.  To re-start the set-up process, run
      /sbin/vboxconfig
    as root
    $ sudo -i
    # /sbin/vboxconfig
    vboxdrv.sh: Stopping VirtualBox services.
    vboxdrv.sh: Building VirtualBox kernel modules.
    

    相关文章

      网友评论

        本文标题:Kubernetes 学习笔记 001

        本文链接:https://www.haomeiwen.com/subject/hhelfhtx.html