基础架构系列篇-常用的K8S指令

设置K8S运行context
kubectl config use-context docker-desktop

查看集群状态
kubectl cluster-info

查看节点
kubectl get nodes

创建控制面板
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml

切换到k8s-for-docker-desktop-1.21.5目录
执行kubectl create -f kubernetes-dashboard.yaml

查看kubernetes-dashboard名称空间的pod
kubectl get pod -n kubernetes-dashboard

开启 API Server 访问代理
kubectl proxy

访问kubernetes-dashboard
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
选择令牌登录

创建令牌
T O K E N = ( ( k u b e c t l − n k u b e − s y s t e m d e s c r i b e s e c r e t d e f a u l t ∣ S e l e c t − S t r i n g " t o k e n : " ) − s p l i t " + " ) [ 1 ] k u b e c t l c o n f i g s e t − c r e d e n t i a l s d o c k e r − d e s k t o p − − t o k e n = " TOKEN=((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")[1] kubectl config set-credentials docker-desktop --token=" TOKEN=((kubectlnkubesystemdescribesecretdefaultSelectString"token:")split"+")[1]kubectlconfigsetcredentialsdockerdesktoptoken="{TOKEN}"
echo $TOKEN
或查看
.kube\config文件里的token参数

安装ingress
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-1.0.4/deploy/static/provider/cloud/deploy.yaml

网络访问异常就从GITHUB下载ingress-nginx
切换目录ingress-nginx-controller-v1.0.4
执行 kubectl apply -f deploy/static/provider/cloud/deploy.yaml
查看 kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx

创建应用
切换k8s-for-docker-desktop-1.21.5目录
执行 kubectl create -f sample/apple.yaml
kubectl create -f sample/banana.yaml
kubectl create -f sample/ingress.yaml

删除应用
kubectl delete -f sample/apple.yaml
kubectl delete -f sample/banana.yaml
kubectl delete -f sample/ingress.yaml

部署nginx
kubectl create deployment nginx --image=nginx

查看pod
kubectl get pod或 kubectl get pods

查看deployment
kubectl get deployment

打开端口
kubectl expose deployment nginx --port=80 --type=NodePort

查看service
kubectl get svc 或 kubectl get service

打开网页访问 集群的 M/S节点IPV4地址:NODEPORT端口

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐