一、安装过程
1.minikube安装依赖
1.1 minikube支持windows、mac、linux系统。这里是基于ubuntu server 20.4系统安装。
1.2 minikube需要资源
- 2个cpu
- 2G内存
- 20G硬盘
- 安装服务器可以连接到互联网
- 虚拟化支持:Docker, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware Fusion/Workstation
1.3 依赖安装
1.3.1 docker安装
ps:这里为了方便直接选择用ubuntu的包管理安装工具安装了。
apt install docker.io -y
1.3.2 conntrack安装
apt install conntrack -y
1.4 kubectl安装
apt-get update && apt-get install -y apt-transport-https;
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -;
cat <<EOF> /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update;
apt-get install -y kubectl
2.minikube安装
2.1 从官网依照系统选择合适的安装包。我使用ubuntu安装的,所以选择ubuntu.
2.2 下载安装
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb;
sudo dpkg -i minikube_latest_amd64.deb
3.minikube命令说明
3.1 minikube帮助
#minikube --help
minikube provisions and manages local Kubernetes clusters optimized for development workflows.
Basic Commands:
start Starts a local Kubernetes cluster
status Gets the status of a local Kubernetes cluster
stop Stops a running local Kubernetes cluster
delete Deletes a local Kubernetes cluster
dashboard Access the Kubernetes dashboard running within the minikube cluster
pause pause Kubernetes
unpause unpause Kubernetes
Images Commands:
docker-env Configure environment to use minikube's Docker daemon
podman-env Configure environment to use minikube's Podman service
cache Add, delete, or push a local image into minikube
image Manage images
Configuration and Management Commands:
addons Enable or disable a minikube addon
config Modify persistent configuration values
profile Get or list the current profiles (clusters)
update-context Update kubeconfig in case of an IP or port change
Networking and Connectivity Commands:
service Returns a URL to connect to a service
tunnel Connect to LoadBalancer services
Advanced Commands:
mount Mounts the specified directory into minikube
ssh Log into the minikube environment (for debugging)
kubectl Run a kubectl binary matching the cluster version
node Add, remove, or list additional nodes
cp Copy the specified file into minikube
Troubleshooting Commands:
ssh-key Retrieve the ssh identity key path of the specified node
ssh-host Retrieve the ssh host key of the specified node
ip Retrieves the IP address of the specified node
logs Returns logs to debug a local Kubernetes cluster
update-check Print current and latest version number
version Print the version of minikube
options Show a list of global command-line options (applies to all commands).
Other Commands:
completion Generate command completion for a shell
Use "minikube <command> --help" for more information about a given command.
3.2 minikube子选项帮助查看
# minikube kubectl -- --help
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
Basic Commands (Beginner):
create Create a resource from a file or from stdin
expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes service
run Run a particular image on the cluster
set Set specific features on objects
Basic Commands (Intermediate):
explain Get documentation for a resource
get Display one or many resources
edit Edit a resource on the server
delete Delete resources by file names, stdin, resources and names, or by resources and label selector
Deploy Commands:
rollout Manage the rollout of a resource
scale Set a new size for a deployment, replica set, or replication controller
autoscale Auto-scale a deployment, replica set, stateful set, or replication controller
Cluster Management Commands:
certificate Modify certificate resources.
cluster-info Display cluster information
top Display resource (CPU/memory) usage
cordon Mark node as unschedulable
uncordon Mark node as schedulable
drain Drain node in preparation for maintenance
taint Update the taints on one or more nodes
Troubleshooting and Debugging Commands:
describe Show details of a specific resource or group of resources
logs Print the logs for a container in a pod
attach Attach to a running container
exec Execute a command in a container
port-forward Forward one or more local ports to a pod
proxy Run a proxy to the Kubernetes API server
cp Copy files and directories to and from containers
auth Inspect authorization
debug Create debugging sessions for troubleshooting workloads and nodes
Advanced Commands:
diff Diff the live version against a would-be applied version
apply Apply a configuration to a resource by file name or stdin
patch Update fields of a resource
replace Replace a resource by file name or stdin
wait Experimental: Wait for a specific condition on one or many resources
kustomize Build a kustomization target from a directory or URL.
Settings Commands:
label Update the labels on a resource
annotate Update the annotations on a resource
completion Output shell completion code for the specified shell (bash, zsh or fish)
Other Commands:
alpha Commands for features in alpha
api-resources Print the supported API resources on the server
api-versions Print the supported API versions on the server, in the form of "group/version"
config Modify kubeconfig files
plugin Provides utilities for interacting with plugins
version Print the client and server version information
Usage:
kubectl [flags] [options]
Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
4.minikube创建本地k8s集群
1.说明
1.minikube有两种模式
- 1.1 虚拟机需要使用bare-metal模式安装。
- 1.2 bare-metal模式说明
- 1.3 因为基于bare-metal模式安装,只有master节点。master节点是污点模式。如果配置应用,需要将pod配置为容忍污点模式。
2.安装k8s集群
minikube start --driver='none' --image-mirror-country=cn --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
3.安装k8s集群和启用web ui
3.1 安装
# 查看安装的k8s集群
root@k8s:~# minikube kubectl -- get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-65c54cc984-7n2n7 1/1 Running 0 2m7s
kube-system etcd-k8s 1/1 Running 0 2m18s
kube-system kube-apiserver-k8s 1/1 Running 0 2m18s
kube-system kube-controller-manager-k8s 1/1 Running 0 2m20s
kube-system kube-proxy-7nnfx 1/1 Running 0 2m7s
kube-system kube-scheduler-k8s 1/1 Running 0 2m21s
kube-system storage-provisioner 1/1 Running 0 2m15s
minikube kubectl -- get po -A
# 启用web ui
minikube dashboard --port=8080 &
3.2 dashboard访问url(只支持在部署k8s的服务器访问,外网访问需要配置代理)
http://127.0.0.1:8080/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-da shboard:/proxy/
4.创建代理
1 minikube kubectl -- proxy --address=0.0.0.0 --accept-hosts='.*' &
5.访问dashboard
浏览器打开下面的地址即可
http://192.168.1.163:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernet es-dashboard:/proxy/#/workloads?namespace=default
二、参考资料
CentOS7 使用minikube 搭建kubernetes 学习环境
VMware centOS7 下通过minikube部署Kubernetes