https://microk8s.io/docs
https://github.com/ubuntu/microk8s
#Ubuntu
sudo apt update
sudo apt install snapd
-snap 已经安装好的工具列表
sudo snap list
#microk8s
-版本
sudo snap info microk8s
sudo snap install microk8s --classic --channel=1.18/stable
sudo snap install microk8s --classic --channel=1.19/beta
-更换版本
sudo snap refresh microk8s --channel=1.19/edge
-卸载
sudo snap remove microk8s
sudo snap install microk8s --classic
sudo usermod -a -G microk8s ubuntu
sudo chown -f -R ubuntu ~/.kube
-查看Kubernetes状态
sudo microk8s status --wait-ready
-访问Kubernetes
sudo microk8s kubectl get nodes
sudo microk8s kubectl get services
sudo alias kubectl='microk8s kubectl'
-获取可用列表
sudo microk8s enable --help
-打开想要的服务
sudo microk8s enable dashboard dns registry istio
-关闭服务
sudo microk8s disable dashboard dns registry istio
-查看服务状态
sudo microk8s status
-排查下安装部署结果
sudo microk8s inspect
-查看当前 Kubernetes pods 状态
sudo microk8s kubectl get pods
-查看当前 Kubernetes查看详细的状态
sudo microk8s.kubectl get pods --all-namespaces
-查看当前这个问题 pod 的详细状态
sudo microk8s.kubectl describe pod
-查看服务状态
sudo microk8s.kubectl get all
#开始使用Kubernetes
sudo microk8s kubectl get all --all-namespaces
-如果您主要使用MicroK8s,则可以在命令行中使用别名mkctl=“microk8s kubectl”使kubectl成为默认命令行。
-还可以通过--kubeconfig参数指向相应的kubeconfig文件来驱动其他Kubernetes集群。
#Kubernetes仪表板
sudo microk8s dashboard-proxy
#开始与停止
sudo microk8s start
sudo microk8s stop
#添加节点node
sudo microk8s add-node
Join node with:
microk8s join ip-172-31-20-243:25000/DDOkUupkmaBezNnMheTBqFYHLWINGDbf
-查看节点
sudo microk8s kubectl get no
-设置故障域
echo "failure-domain=42" > /var/snap/microk8s/current/args/ha-conf
microk8s.stop
microk8s.start
#移出节点
sudo microk8s leave
sudo microk8s remove-node 10.22.254.79
sudo microk8s remove-node 10.22.254.79 --force
#高可用性
在MicroK8s的1.19版本中,默认启用了HA。如果集群由三个或更多个节点组成,数据存储将被复制到各个节点上,并且它将对单个故障具有弹性(如果一个节点出现问题,则工作负载将继续不间断地运行)。
-查看状态
sudo microk8s status
microk8s is running
high-availability: yes
datastore master nodes: 10.128.63.86:19001 10.128.63.166:19001 10.128.63.43:19001
datastore standby nodes: none
#重载 snap 服务
sudo systemctl daemon-reload && systemctl restart snapd
#升级现有集群
sudo snap refresh microk8s --channel=1.19/stable
master node:
sudo microk8s enable ha-cluster
任何已经是集群中的节点的机器都需要退出并重新连接才能建立HA。
要做到这一点,请循环遍历节点,以排出、移除并重新加入它们:
sudo microk8s kubectl drain <node> --ignore-daemonsets
sudo microk8s leave
sudo microk8s add-node
sudo microk8s join
#运行服务
microk8s.kubectl run hello-minikube --image=registry.cn-hangzhou.aliyuncs.com/google-containers/echoserver:1.4 --port=8080
microk8s.kubectl expose deployment hello-minikube
-当前的部署情况:
microk8s.kubectl get all --all-namespaces
-验证:
curl http://10.152.183.119:8080/123
microk8s kubectl create deployment nginx --image=nginx
microk8s kubectl get pods
#为了尽可能轻量级,MicroK8s只安装可用Kubernetes安装的基础设备
api-server
controller-manager
scheduler
kubelet
cni
kube-proxy
#MicroK8s Addons
ambassador # API网关和入口大使
cilium # SDN,快速和全网络策略
dashboard # The Kubernetes dashboard
dns # CoreDNS
fluentd # Elasticsearch-Fluentd-Kibana logging and monitoring
gpu # Automatic enablement of Nvidia CUDA
helm # Helm 2 - the package manager for Kubernetes
helm3 # Helm 3 - Kubernetes package manager
host-access # 允许Pods顺利地连接到主机服务
ingress # 创建Ingress控制器
istio # 启用核心的Istio服务
jaeger # Kubernetes Jaeger operator with its simple config
keda # Kubernetes-based Event Driven Autoscaling
knative # The Knative framework on Kubernetes.
kubeflow # Kubeflow for easy ML deployments
linkerd # Linkerd is a service mesh for Kubernetes and other frameworks
metallb # Loadbalancer for your Kubernetes cluster
metrics-server # K8s Metrics Server for API access to service metrics
multus # Multus CNI enables attaching multiple network interfaces to pods
portainer # Portainer UI for your Kubernetes cluster
prometheus # Prometheus operator for monitoring and logging
rbac # Role-Based Access Control for authorisation
registry # 部署私有Docker注册中心 on localhost:32000
storage # 让你可以使用主机上的存储。
traefik # traefik Ingress controller for external access
#Services and ports
Services binding to the default Host interface
| PORT | SERVICE | ACCESS RESTRICTIONS |
|---|
| 16443 | API server | SSL encrypted. Clients need to present a valid password from a Static Password File. |
| 10250 | kubelet | Anonymous authentication is disabled. X509 client certificate is required. |
| 10255 | kubelet | Read only port for the Kubelet. |
| 25000 | cluster-agent | Proper token required to authorise actions. |
| 12379 | etcd | SSL encrypted. Client certificates required to connect. |
| 10257 | kube-controller | Serve HTTPS with authentication and authorization. |
| 10259 | kube-scheduler | Serve HTTPS with authentication and authorization. |
| 19001 | dqlite | SSL encrypted. Client certificates required to connect. |
Services binding to the localhost interface
| PORT | SERVICE | DESCRIPTION |
|---|
| 10248 | kubelet | Localhost healthz endpoint. |
| 10249 | kube-proxy | Port for the metrics server to serve on. |
| 10251 | kube-schedule | Port on which to serve HTTP insecurely. |
| 10252 | kube-controller | Port on which to serve HTTP insecurely. |
| 10256 | kube-proxy | Port to bind the health check server. |
| 2380 | etcd | Used for peer connections. |
| 1338 | containerd | Metrics port |