只支持单节点的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
- 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
- make the kubectl binary executable chmod +x ./kubectl
- move the binary in to your PATH sudo mv ./kubectl /usr/local/bin/kubectl
- 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
- 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上运行)
- install Chocolatey
- choco install kubernetes-cli
- 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