首页 > 其他分享 >k8s 操作命令-合集List

k8s 操作命令-合集List

时间:2024-04-23 16:33:05浏览次数:31  
标签:kubectl 操作命令 get -- List deployment pod k8s

k8s 操作命令 合集List

 

---------------k8s基本常用的命令-----------------------------------------

1、创建资源
kubectl create deployment nginx --image=nginx
2、列出资源
kubectl get pods
3、描述资源
kubectl describe pod <pod-name>
4、删除资源
kubectl delete deployment <deployment-name>
5、运行配置文件(.yaml/.yml)
kubectl apply -f ./nginx.yaml
6、执行容器
kubectl exec -it <pod-name> -- /bin/bash
7、缩放资源
kubectl scale deployment <deployment-name> --replicas=3
8、更新资源
kubectl set image deployment/<deployment-name> nginx=ngix:1.9.1
9、导出资源
kubectl get deployment <deployment-name> -o yaml
10、更新kubernetes 集群
kubectl apply -f ./cluster-config.yaml
---------------k8s基本常用的命令-----------------------------------------

 

 


你可以通过 kubectl <command> --help 来查看每个命令的详细帮助信息。

一、K8S最常用命令如下:
1、获取pod信息:kubectl get pod
2、查看指定pod的日志信息:kubectl logs -f --tail(最后多少行) 500 podName(pod名)
3、查看pod的描述信息:kubectl describe pod podName
4、查看节点信息:kubectl get nodes
5、查看pod的详细信息,以yaml或者json格式展示:kubectl get pods -o yaml、kubectl get pods -o json
6、查看所有名称空间的pod:kubectl get pod -A
7、查看指定pod的环境变量:kubectl exec podName env
8、查看所有的service信息:kubectl get svc -A
9、查看集群资源(ComponentStatuses)信息:kubectl get cs
10、查看所有名称空间:kubectl get ns
11、查看集群信息:kubectl cluster-info 、kubectl cluster-info dump
12、进入pod容器:kubectl exec -it podName -n nsName /bin/sh 、kubectl exec -it podName -n nsName /bin/bash
13、删除指定的pod:kubectl delete pod podName
14、删除指定命名空间的pod:kubectl delete pod -n test podName
15、编辑资源:kubectl edit pod podName
16、获取pod详细信息:kubectl get pod -o wide

二、k8s操作命令详解:
1、基础操作命令
alias k=kubectl echo 'alias k=kubectl' >>~/.bashrc
kubectl get pods -o=json
kubectl get pods -o=yaml
kubectl get pods -o=wide
kubectl get pods -n=<namespace_name>
kubectl create -f ./
kubectl logs -l name=

2、资源相关
kubectl create -f – Create objects.
kubectl create -f – Create objects in all manifest files in a directory.
kubectl create -f <'url'> – Create objects from a URL.
kubectl delete -f – Delete an object.

3、集群相关
kubectl cluster-info – Display endpoint information about the master and services in the cluster.
kubectl version – Display the Kubernetes version running on the client and server.
kubectl config view – Get the configuration of the cluster.
kubectl config view -o jsonpath='{.users[*].name}' – Get a list of users.
kubectl config current-context – Display the current context.
kubectl config get-contexts – Display a list of contexts.
kubectl config use-context – Set the default context.
kubectl api-resources – List the API resources that are available.
kubectl api-versions – List the API versions that are available. kubectl get all --all-namespaces

4、Daemonsets 相关
kubectl get daemonset – List one or more daemonsets.
kubectl edit daemonset <daemonset_name> – Edit and update the definition of one or more daemonset.
kubectl delete daemonset <daemonset_name> – Delete a daemonset.
kubectl create daemonset <daemonset_name> – Create a new daemonset.
kubectl rollout daemonset – Manage the rollout of a daemonset.
kubectl describe ds <daemonset_name> -n <namespace_name> – Display the detailed state of daemonsets within a namespace.

5、Deployments相关
kubectl get deployment – List one or more deployments.
kubectl describe deployment <deployment_name> – Display the detailed state of one or more deployments.
kubectl edit deployment <deployment_name> – Edit and update the definition of one or more deployments on the server.
kubectl create deployment <deployment_name> – Create a new deployment.
kubectl delete deployment <deployment_name> – Delete deployments.
kubectl rollout status deployment <deployment_name> – See the rollout status of a deployment.
kubectl set image deployment/ =image: – Perform a rolling update (K8S default), set the image of the container to a new version for a particular deployment.
kubectl rollout undo deployment/ – Rollback a previous deployment.
kubectl replace --force -f – Perform a replace deployment — Force replace, delete and then re-create the resource.

6、事件相关
kubectl get events – List recent events for all resources in the system.
kubectl get events –field-selector type=Warning – List Warnings only.
kubectl get events --sort-by=.metadata.creationTimestamp – List events sorted by timestamp.
kubectl get events --field-selector involvedObject.kind!=Pod – List events but exclude Pod events.
kubectl get events --field-selector involvedObject.kind=Node, involvedObject.name=<node_name> – Pull events for a single node with a specific name.
kubectl get events --field-selector type!=Normal – Filter out normal events from a list of events.

7、日志相关
kubectl logs <pod_name> – Print the logs for a pod.
kubectl logs --since=6h <pod_name> – Print the logs for the last 6 hours for a pod.
kubectl logs --tail=50 <pod_name> – Get the most recent 50 lines of logs.
kubectl logs -f <service_name> [-c <$container>] – Get logs from a service and optionally select which container.
kubectl logs -f <pod_name> – Print the logs for a pod and follow new logs.
kubectl logs -c <container_name> <pod_name> – Print the logs for a container in a pod.
kubectl logs <pod_name> pod.log – Output the logs for a pod into a file named ‘pod.log'.
kubectl logs --previous <pod_name> – View the logs for a previously failed pod.

8、Namespace 相关
kubectl create namespace <namespace_name> – Create a namespace.
kubectl get namespace <namespace_name> – List one or more namespaces.
kubectl describe namespace <namespace_name> – Display the detailed state of one or more namespaces.
kubectl delete namespace <namespace_name> – Delete a namespace.
kubectl edit namespace <namespace_name> – Edit and update the definition of a namespace.
kubectl top namespace <namespace_name> – Display Resource (CPU/Memory/Storage) usage for a namespace.

9、Nodes 相关
kubectl taint node <node_name> – Update the taints on one or more nodes.
kubectl get node – List one or more nodes.
kubectl delete node <node_name> – Delete a node or multiple nodes.
kubectl top node <node_name> – Display Resource usage (CPU/Memory/Storage) for nodes.
kubectl get pods -o wide | grep <node_name> – Pods running on a node.
kubectl annotate node <node_name> – Annotate a node.
kubectl cordon node <node_name> – Mark a node as unschedulable.
kubectl uncordon node <node_name> – Mark node as schedulable.
kubectl drain node <node_name> – Drain a node in preparation for maintenance.
kubectl label node – Add or update the labels of one or more nodes.

10、Pods 操作相关
kubectl get pod – List one or more pods.
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' – List pods Sorted by Restart Count.
kubectl get pods --field-selector=status.phase=Running – Get all running pods in the namespace.
kubectl delete pod <pod_name> – Delete a pod.
kubectl describe pod <pod_name> – Display the detailed state of a pods.
kubectl create pod <pod_name> – Create a pod.
kubectl exec <pod_name> -c <container_name> – Execute a command against a container in a pod. Read more: Using Kubectl Exec: Connect to Your Kubernetes Containers
kubectl exec -it <pod_name> /bin/sh – Get an interactive shell on a single-container pod.
kubectl top pod – Display Resource usage (CPU/Memory/Storage) for pods.
kubectl annotate pod <pod_name> – Add or update the annotations of a pod.
kubectl label pods <pod_name> new-label= – Add or update the label of a pod.
kubectl get pods --show-labels – Get pods and show labels.
kubectl port-forward : – Listen on a port on the local machine and forward to a port on a specified pod.

11、Replication Controller 相关
kubectl get rc – List the replication controllers.
kubectl get rc --namespace=”<namespace_name>” – List the replication controllers by namespace.

12、ReplicaSets 相关
kubectl get replicasets – List ReplicaSets.
kubectl describe replicasets <replicaset_name> – Display the detailed state of one or more ReplicaSets.
kubectl scale --replicas=[x] – Scale a ReplicaSet.

13、Sercrets 相关
kubectl create secret – Create a secret.
kubectl get secrets – List secrets.
kubectl describe secrets – List details about secrets.
kubectl delete secret <secret_name> – Delete a secret.
14、Services 相关
kubectl get services – List one or more services.
kubectl describe services – Display the detailed state of a service.
kubectl expose deployment [deployment_name] – Expose a replication controller, service, deployment, or pod as a new Kubernetes service.
kubectl edit services – Edit and update the definition of one or more services

15、Service Account相关
kubectl get serviceaccounts – List service accounts.
kubectl describe serviceaccounts – Display the detailed state of one or more service accounts.
kubectl replace serviceaccount – Replace a service account.
kubectl delete serviceaccount <service_account_name> – Delete a service account

16、StatefulSets 相关
kubectl get statefulset – List StatefulSet
kubectl delete statefulset/[stateful_set_name] --cascade=false – Delete StatefulSet only (not pods).

标签:kubectl,操作命令,get,--,List,deployment,pod,k8s
From: https://www.cnblogs.com/chendezhen/p/18153162

相关文章

  • centos8报错错误:为 repo 'appstream' 下载元数据失败 : Cannot prepare internal mirr
    出现如下错误的错误:为repo‘appstream’下载元数据失败:Cannotprepareinternalmirrorlist:NoURLsinmirrorlist原因在2022年1月31日,CentOS团队终于从官方镜像中移除CentOS8的所有包。CentOS8已于2021年12月31日寿终正非,但软件包仍在官方镜像上保留了一段时间。现在......
  • list all possible combination of group separator and decimal separator by iterat
    一共有7种子组合01[,2C][.2E]en-US02[C2A0][,2C]fr-FR03[.2E][,2C]da-DK04[’E28099][.2E]de-CH05[C2A0][.2E]tn-BW06[,2C][/2F]fa-IR07[’E28099][,2C]wae-CHvarlist=CultureInfo.GetCultures(CultureTypes.AllCultures);Dictionary<string,List<str......
  • [Violation] Added non-passive event listener to a scroll-blocking <某些> 事件. C
    今天在网页控制台看到了这个警告[Violation]Addednon-passiveeventlistenertoascroll-blocking<某些>事件.Considermarkingeventhandleras'passive'tomakethepagemoreresponsive.See然后我发现是一款浏览器叫“沉浸式翻译-网页翻译插件|PDF翻译|......
  • 【Redis】Redis的操作命令(二)——Redis 字符串(String)
    常见的Redis字符串命令如下:命令说明例子SETkeyvalue设置指定key的值 GETkey获取指定key的值 GETRANGEkeystartend返回key中字符串值的子字符 GETRANGEmykey03 GETSETkeyvalue将给定key的值设为value,并返回key的旧值(oldvalu......
  • AList基础使用
    AList是一个支持多种存储的文件列表程序,跨平台,开源免费。官网:[https://alist.nn.ci/zh/]开源地址:[https://github.com/alist-org/alist]alist支持挂载本地存储器和一些云盘(谷歌、百度、阿里云盘等),本教程在Ubuntu中,使用alist挂载本地存储器,作为一个局域网nas使用。alist可以......
  • Delphi10.3如何将ListBox1项,拖动 到 右边Memo1当前输入项
    01]ListBox1的DragMode设置为dmAutomatic02】Memo1的OnGragOver事件和OnDragDrop事件 procedureTForm8.Memo1DragOver(Sender,Source:TObject;X,Y:Integer;State:TDragState;varAccept:Boolean);beginifTListBox(Source)=ListBox1thenAccept:=true;end;......
  • k8s serviceIP: range is full
    创建svc报错Internalerroroccurred:failedtoallocateaserviceIP:rangeisfullk8ssvc的网段默认ip为256个,在master节点的/etc/kubernetes/manifests/kube-apiserver.yaml和/etc/kubernetes/manifests/kube-controller-manager.yaml中的service-cluster-ip-range进行......
  • k8s node节点报错 dial tcp 127.0.0.1:8080: connect: connection refused
    前言在搭建好kubernetes环境后,master节点拥有control-plane权限,可以正常使用kubectl。但其他node节点无法使用kubectl命令,即使同步过去/root/.kube/config文件到各个node节点上,也不行。解决检查KUBECONFIG变量:确保KUBECONFIG环境变量正确设置。KUBECONFIG......
  • redis list数据结构操作学习
    转自:https://zhuanlan.zhihu.com/p/765785471.插入元素>rpushmylistA#从右侧插入(integer)1>rpushmylistB(integer)2>lpushmylistfirst(integer)3>lrangemylist0-1//这里使用0-1表示显示所有元素,注意是:0空格-1,0代表第一个元素,-1代表最后......
  • QML::ListView
    ListView1.0ListView基础使用方法//ListView01.qml1、通过Component定义Delegate2、通过ListModel定义mode,通过ListElement定义数据类型3、定义ListView,通过delegate和model属性绑定mode和DelegateimportQtQuick2.2importQtQuick.Controls1.2importQtQuick.Layout......