使用Minikube来在本地运行Kubernetes

只支持单节点的Kubernetes集群,并且需要运行虚拟机,所以只能运行在裸机上或者VMware虚拟机上。

See the link on https://kubernetes.io/docs/getting-started-guides/minikube/

Minikube is a tool that makes it easy to run Kubernetes locally

Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day

Install MiniKube

  • enable VT-x or AMD-v
  • install virtualbox

  • 从官方网站下载RPM包

  • 运行 rpm -ivh * 来进行安装

  • install kubectl

  • On Linux

    1. download the latest release with command: curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
    2. make the kubectl binary executable  chmod +x ./kubectl
    3. move the binary in to your PATH  sudo mv ./kubectl /usr/local/bin/kubectl
    4. check kubectl config file, it will be auto create when you create a cluster using kube-up.sh or successfully deploy a Minikube cluster
  • it is at ~/.kube/config.

  • Check the kuberctl configuraion, run this command kubectl cluster-info if a url response then it worked property
  • if something error then run command kubectl cluster-info dump to check reason

    1. Enabling shell autocompletion, kubectl includes autocompletion support, which can save a lot of typing!
  • run command source <(kubectl completion bash)

  • To add kubectl autocompletion to your profile, so it is automatically loaded in future shells run: echo “source <(kubectl completion bash)” >> ~/.bashrc

  • On Windows (不推荐在Windows上运行)

    1. install Chocolatey
    2. choco install kubernetes-cli
    3. do configuration 
      cd C:\users\yourusername (Or wherever your %HOME% directory is)
      mkdir .kube
      cd .kube
      touch config
  • install Minikube

  • run curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.24.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

  • Run minikube 

  • minikube start –vm-driver=virtualbox 注意必须要指定driver

  • 如果遇到执行权限的问题就执行 为 /usr/local/bin  /etc/kubernetes, /var/lib/localkube  这两个文件夹赋 777 权限

  • 可以打开Kubernetes控制台

  • minikube dashboard

  • 使用kubectl 管理Kubernetes

  • kubectl run hello-minikube –image=k8s.gcr.io/echoserver:1.4 –port=8080  运行一个Docker容器

  • kubectl run mydocker –image=jialei123123/mydocker –port=8088

  • kubectl expose deployment hello-minikube –type=NodePort   讲deployment hello-minikube服务暴露出来

  • kubectl expose deployment mydocker –type=NodePort

  • kubectl get pod  查看pod信息,非系统pod

  • kubectl delete deployment hello-minikube  删除之前创建的hello-minikube
  • minikube stop 停止minikube

  • minikube 管理命令

  • minikube delete 用来删除当前的 cluster

  • minikube status 查看状态
  • minikube docker-env 
  • eval $(minikube docker-env) 配置docker的环境变量,操作以后就可以直接使用docker命令访问到minikube中的docker镜像

  • 在centos 7 如果现实有错,那么要检查 /etc/sysconfig/docker 中的配置

  • kubectl get nodes 显示本地节点数

  • kubectl get all 显示所有相关信息
  • minikube start 启动的时候会创建一个名称为 minikube的 “kubectl context”, 理论性这个配置会被自动加载,当然也可以在运行kubectl的时候指定 例如: kubectl get pods –context=minikube
  • minikube dashboard 启动 Kubernetes 的 dashboard
  • minikube service [-n namespace] [–url] name 查看一个service

  • 配置kubernets —- 在minikube start命令后面使用 –extra-config 

  • 设置 Maxpod  –extra-config=kubelet.MaxPods=5

  • 在linux还可以使用KVM作为虚拟机,有的时候virtualbox无法使用的时候,可以使用kvm

  • 其他步骤都一样,是只使用kvm的话,需要先安装kvm driver

  • sudo yum install libvirt-daemon-kvm qemu-kvm
  • sudo usermod -a -G libvirt $(whoami) 将当期用户加入到libvirtd group
  • newgrp libvirt 使之前的修改生效
  • 启动的时候使用命令 minikube start –vm-driver kvm
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值