uniquejava / blog

My notes regarding the vibrating frontend :boom and the plain old java :rofl.
Creative Commons Zero v1.0 Universal
11 stars 5 forks source link

minikube #252

Open uniquejava opened 5 years ago

uniquejava commented 5 years ago

呃.. https://codefresh.io/kubernetes-tutorial/local-kubernetes-mac-minikube-vs-docker-desktop/

国内使用minikube: https://cloud.tencent.com/developer/article/1015023

生产环境的kubernetes版本号: 1.10.11

极速

安装docker
安装kubernetes client(对应kubectl命令) 
安装kubernete server(对应minikube命令)
安装VM virtual box

brew update && brew install kubectl && brew cask install docker minikube virtualbox
docker --version
minikube version
kubectl version --client

# 管理

启动minikube
minikube start --vm-driver=none --registry-mirror=https://registery.docker-cn.com --kubernetes-version v1.12.1

切换k8s context
kubectl config use-context minikube

minikube dahsboard

# 部署
kubectl run my-nginx --image=nginx --port=80
kubectl expose deployment my-nginx --type=NodePort 
Kubectl scale --replicas=3 deployment/my-nginx
kubect get pods

安装minikube

brew cask install minikube

离线下载 minikube-v0.31.0.iso

https://storage.googleapis.com/minikube/iso/minikube-v0.31.0.iso 下载到本地, 然后搭一个静态服务器, 保证这样能访问到: http://localhost:8000/minikube-v0.31.0.iso

后面minikube start时加iso-url参数指向本地URL.

或者放到这里/Users/xxx/.minikube/cache/iso/minikube-v0.31.0.iso, 它应该能读到.

安装VM, 使用hyperkit(替换virtualbox)

Linux环境比如ubuntu不需要装VM、 mac下有多种方式见 minikube官网

见: https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver

curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit \
&& sudo install -o root -g wheel -m 4755 docker-machine-driver-hyperkit /usr/local/bin/

启动minikube (开启activity monitor监控下载速度)

NOTE: (中途提示Downloading kubeadm v1.10.0 需要开启NDVPN US, 不然会卡在那timeout)

启动minikube start --iso-url="https://storage.googleapis.com/minikube/iso/minikube-v0.31.0.iso" --vm-driver=hyperkit --alsologtostderr --v 10

minikube start --vm-driver=hyperkit --iso-url=http://localhost:8000/minikube-v0.31.0.iso --kubernetes-version v1.10.11

minikube start --vm-driver=none --iso-url file://tmp/minikube-v0.23.5.iso --kubernetes-version v1.7.5 --extra-config=apiserver.Service.NodePortRange=0-60000

参考离线安装minikube: https://blog.zhoulouzi.com/2017/10/minikube/

错误排查

若启动时出现错误,请执行以下命令,再重新执行启动命令。

$ minikube delete 删除本地集群
$ rm -rf ~/.minikube  # MINIKUBE的配置文件

其它配置文件

$ rm -rf ~/.docker  #  Docker配置文件
$ rm -rf ~/.kube  # DOCKER自带的K8S配置文件

Docker for Mac 自带的 k8s 会与 minikube 冲突,

请以下命令进行切换

#如果未装K8s
$ brew install kubectl
$ kubectl config get-contexts
CURRENT   NAME                 CLUSTER                      AUTHINFO             NAMESPACE
          docker-for-desktop   docker-for-desktop-cluster   docker-for-desktop
*         minikube             minikube                     minikube
# 切换到 docker 自带的 k8s
$ kubectl config use-context docker-for-desktop
# 切换到 minikube
$ kubectl config use-context minikube

常用命令

minikube version
minikube status
minikube start/stop
minikube start --cpus=4 --memory=4000
minikube ssh
minikube ip
minikube dashboard
重装minikube delete && minikube start
kubectl run ghost --image=ghost:0.9 生成deployment object
kubectl expose deployments ghost --port=2368 --type=NodePort 生成service object.
kubectl get pods,rs,deployments,services
kubectl get all 相当于linux系统中的ps命令
kubectl logs <pod_name_here>
kubectl service ghost

kubectl get xxx列表及缩写

configmaps (aka cm)
daemonsets (aka ds)
deployments (aka deploy)
endpoints (aka ep)
events (aka ev)
horizontalpodautoscalers (aka hpa)
ingresses (aka ing)
namespaces (aka ns)
nodes (aka no)
persistentvolumeclaims (aka pvc)
persistentvolumes (aka pv)
pods (aka po)
replicasets (aka rs)
replicationcontrollers (aka rc)
resourcequotas (aka quota)
serviceaccounts (aka sa)
services (aka svc)