Kubernetes-On-MacOS-minikube

安装软件

1
2
3
4
brew install docker
brew install virtualbox
brew install kubectl
brew install minikube

minikube 命令

start

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
## minikube 支持三种HyperKit、VirtualBox、Parallels Desktop、VMware Fusion
## 设置默认 driver
minikube config set driver virtualbox

## 启动集群
## 简单版本
minikube start
## 详细参数版本
minikube start --v=0 --kubernetes-version v1.20.7 --cpus 4 --memory=8192 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --driver=virtualbox

## 参数说明
--v 日志等级
0 INFO level logs
1 WARNING level logs
2 ERROR level logs
3 libmachine logging
7 libmachine --debug level logging
--kubernetes-version 指定版本
--cpus 4 --memory=8192 指定资源
--image-repository 指定镜像代理
--driver=virtualbox 指定 driver, 如果设置过默认 driver 这个可以忽略

dashboard

1
2
3
4
5
6
## 在新的终端运行命令
## 打开仪表盘,默认会打开一个浏览器页面
minikube dashboard

## 打开仪表盘,但是不打开浏览器
minikube dashboard --url

addons

1
2
3
4
5
6
7
## addons 相关命令
## 启用 ingress
minikube addons enable ingress
## 禁用 ingress
minikube addons disable ingress

minikube addons list

service

1
2
## 运行 kubectl 创建好的服务
minikube service hello-node

stop delete

1
2
3
4
## 关闭 minikube virtual machine
minikube stop
## 删除 minikube virtual machine
minikube delete

kubectl 命令

deployment

1
2
3
4
## 创建 deployment
kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
## 查看 deployment
kubectl get deployments

event

1
2
## 查看 cluster events
kubectl get events

configuration

1
2
## 查看 cubectl configuration
kubectl config view

pods

1
2
3
4
5
6
7
8
9
10
## 查看 pod
#### 查看 namespace 为 default 的 pod
kubectl get pods
#### 查看所有 namespace 的 pod
kubectl get pods --all-namespaces -o wide
#### 查看指定 namespace 为 kube-system 的 pod
kubectl get pods -n kube-system -o wide

## 查询详细
kubectl describe pod PodName

services

1
2
3
4
5
6
7
8
9
10
11
12
13
14
## 查看你创建的 pod,service
kubectl get pod,svc -n kube-system

## 查看 service
kubectl get services --all-namespaces
## 创建 service
kubectl expose deployment hello-node --type=LoadBalancer --port=8080
## 查看 service
kubectl get services --all-namespaces
## 注: 对比第一次查看 service, 此时多了一个刚刚 expose 的 hello-node 服务
## 原因: 默认 pod都是只在集群内部可用,只有expose之后,外部网络才可以访问到

## minikube 运行服务
minikube service hello-node

cleanup

1
2
3
## 删除 service deploy, 即 清理资源
kubectl delete service hello-node
kubectl delete deployment hello-node

参考资料

在MacOS上安装kubernetes
在MAC上安装K8S (kubernets) for Docker Desktop
手摸手教你从开发到部署(CI/CD)GO微服务系列
minikube docs
k8s tutorials Hello Minikube