minikube
服务器启动
sh
# 启动集群
minikube start
# 启动集群并使用docker驱动
minikube start --driver=docker
To make docker the default driver:
minikube config set driver docker
# 查看节点。kubectl 是一个用来跟 K8S 集群进行交互的命令行工具
kubectl get node
# 停止集群
minikube stop
# 清空集群
minikube delete --all
# 安装集群可视化 Web UI 控制台
minikube dashboard
minikube 安装以后可以再安装kubectl ,不必使用minikube kubectl 来用
kubectl cluster-info 查看集群配置是否正确
kubectl容器操作
c
kubectl get namespace//获得所有命名空间
kubectl get pod --all-namespaces -o wide//获得命名空间下的所有容器
通过kubectl get pods查询,然后通过下面命令进入
kubectl exec -it nas-all-0 /bin/bash
新版使用这个进入容器
kubectl exec test-pod -it -- /bin/bash
//进入命名空间下的容器,application是命名空间,psqls-0是容器
kubectl exec -it -n application psqls-0 /bin/bash
//拷贝内容内文件,拷贝出来
kubectl cp -n application psqls-0:/var/lib/postgresql/data/pg_wal /home
//拷贝进去
kubectl cp /home/dades/pg_wal -n application psqls-0:/var/lib/postgresql/data/pg_wal
kubect pod 操作
sh
kubectl get pod -o wide
kubectl get pod -o wide -n <namespace-name>
# 查看pod详细信息
kubectl describe pod <pod-name>
Name: testapp
Namespace: default #在哪个namespace下面
Priority: 0
Service Account: default
Node: minikube/192.168.49.2 #在哪个node下面,后面是nodeIp
Start Time: Wed, 31 Jan 2024 15:50:21 +0800
Labels: run=testapp #对应的标签选择器key:value
Annotations: <none>
Status: Running
IP: 10.244.0.11
IPs:
IP: 10.244.0.11
Containers:
testapp:
#
Container ID: docker://a10cb23fd7cd835a584865076e134278bb77f16282a97208661b95a97a6744e0
Image: ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s:v1
Image ID: docker-pullable://ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s@sha256:9b452816d6493045a21d8b3d6a851f21ca2e50c86cd57ba8c41141f001d9911d
Port: <none>
Host Port: <none>
State: Running
Started: Wed, 31 Jan 2024 15:51:48 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-58tk8 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-58tk8:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 51m default-scheduler Successfully assigned default/testapp to minikube
# 接受命令,分发任务
Normal Pulling 51m kubelet Pulling image "ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s:v1"
# 拉取镜像
Normal Pulled 49m kubelet Successfully pulled image "ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s:v1" in 1m25.557s (1m25.557s including waiting)
# 拉取成功
# 创建容器
Normal Created 49m kubelet Created container testapp
Normal Started 49m kubelet Started container testapp
pod 其他操作
sh
# 查看日志
kubectl logs <pod-name>
# 进入容器
kubectl exec -it <pod-name> -- /bin/bash
dashboard
minikube dashboard &
返回的url
http://127.0.0.1:42005/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
为访问地址但此地址只是容器代理出来的地址,只能本机内网访问,要想在外网访问
dashboard
的UI 界面,需要使用kubectl做一层代理。
kubectl proxy --port=端口号(一个没有被占用的就可以) --address='机器或者虚拟机地址' --accept-hosts='^.*' &
以上命令代理后,访问http://机器公网IP:上面配置的端口号/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy
/ 就可以访问到dashboard 的UI 界面