只支持單節(jié)點(diǎn)的Kubernetes集群碱蒙,并且需要運(yùn)行虛擬機(jī),所以只能運(yùn)行在裸機(jī)上或者VMware虛擬機(jī)上。
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
從官方網(wǎng)站下載RPM包
運(yùn)行 rpm -ivh *** 來(lái)進(jìn)行安裝
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上運(yùn)行)
- 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
如果遇到執(zhí)行權(quán)限的問(wèn)題就執(zhí)行 為 /usr/local/bin /etc/kubernetes, /var/lib/localkube 這兩個(gè)文件夾賦 777 權(quán)限
可以打開(kāi)Kubernetes控制臺(tái)
minikube dashboard
使用kubectl 管理Kubernetes
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080 運(yùn)行一個(gè)Docker容器
kubectl run mydocker --image=jialei123123/mydocker --port=8088
kubectl expose deployment hello-minikube --type=NodePort 講deployment hello-minikube服務(wù)暴露出來(lái)
kubectl expose deployment mydocker --type=NodePort
kubectl get pod 查看pod信息眶明,非系統(tǒng)pod
kubectl delete deployment hello-minikube 刪除之前創(chuàng)建的hello-minikube
minikube stop 停止minikube
minikube 管理命令
minikube delete 用來(lái)刪除當(dāng)前的 cluster
minikube status 查看狀態(tài)
minikube docker-env
eval $(minikube docker-env) 配置docker的環(huán)境變量,操作以后就可以直接使用docker命令訪問(wèn)到minikube中的docker鏡像
在centos 7 如果現(xiàn)實(shí)有錯(cuò)筐高,那么要檢查 /etc/sysconfig/docker 中的配置
kubectl get nodes 顯示本地節(jié)點(diǎn)數(shù)
kubectl get all 顯示所有相關(guān)信息
minikube start 啟動(dòng)的時(shí)候會(huì)創(chuàng)建一個(gè)名稱為 minikube的 "kubectl context", 理論性這個(gè)配置會(huì)被自動(dòng)加載,當(dāng)然也可以在運(yùn)行kubectl的時(shí)候指定 例如: kubectl get pods --context=minikube
minikube dashboard 啟動(dòng) Kubernetes 的 dashboard
minikube service [-n namespace] [--url] name 查看一個(gè)service
配置kubernets ---- 在minikube start命令后面使用 --extra-config
設(shè)置 Maxpod --extra-config=kubelet.MaxPods=5
在linux還可以使用KVM作為虛擬機(jī)丑瞧,有的時(shí)候virtualbox無(wú)法使用的時(shí)候柑土,可以使用kvm
其他步驟都一樣,是只使用kvm的話绊汹,需要先安裝kvm driver
sudo yum install libvirt-daemon-kvm qemu-kvm
sudo usermod -a -G libvirt $(whoami) 將當(dāng)期用戶加入到libvirtd group
newgrp libvirt 使之前的修改生效
啟動(dòng)的時(shí)候使用命令 minikube start --vm-driver kvm