k8s 操作命令(合集List)

这篇具有很好参考价值的文章主要介绍了k8s 操作命令(合集List)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

k8s 操作命令 合集List

一、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).文章来源地址https://www.toymoban.com/news/detail-518970.html

到了这里,关于k8s 操作命令(合集List)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • k8s 常用命令

    资源类型 资源简称 node no namespaces ns deployment deploy ReplicaSet rs pod po service svc ingress ing DaemonSets ds StatefulSets sts ConfigMap cm PersistentVolume pv PersistentVolumeClaim pvc HorizontalPodAutoscaler hpa ComponentStatus cs 部署上边的yaml资源信息 也可以这样使用命令行方式,直接创建 1.1 查看k8s版本信息 1.

    2023年04月08日
    浏览(74)
  • ​k8s常用命令 ​

    1. 创建资源 kubectl run 创建并运行一个或多个容器镜像。 * 创建一个deployment或job来管理容器* 。 语法 :kubectl run NAME --image=image [--env=\\\"key=value\\\"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...] kubectl create kubectl apply 2. 标签操作 查询标签 添加

    2024年02月01日
    浏览(32)
  • k8s常用命令

    目录 一、namespace 1.查看所有namespace 2.查看指定的namespace 3.查看namespace并指定输出格式 4.查看namespace详情 5.创建namespace 6.删除namespace 7.通过yaml文件创建、删除namespace 二、pod 1.创建并运行pod 2.查看pod信息 3.查看pod详情 4.获取pod IP 5.删除指定pod 6.查看pod资源配置项 7.设置pod镜像拉

    2024年02月06日
    浏览(29)
  • java 对接 k8s API、K8s基本架构、k8s常用命令

    引言: 当容器部署涉及到 多个节点 服务器,用docker、docker-compose 来部署就不是那么方便了,不能统一控制,不方便伸缩,配置统一管理、版本控制;当我们业务涉及到集群容器部署时,就考虑K8s、K3s 来实现。 k8s 架构组成: (一)Master :apiserver、scheduler、controller-manager 以

    2024年02月16日
    浏览(30)
  • 06.K8S常用命令

    1、label 添加label语法 kubectl label nodes node-name label-key=label-value 删除label语法 kubectl label nodes node-name label-key- 修改Label的值 语法: 需要加上–overwrite参数 kubectl label nodes node-name label-key=label-value --overwrite 查看现有node及label kubectl get node --show-labels 2、apply 创建configmap kubectl create con

    2024年02月08日
    浏览(26)
  • K8S常用命令整理

    K8S所有的命令行操作本质是对资源的CRUD有一个对应关系,使用YAML描述资源的关系,使用cli对资源进行各种操作; 因为K8S命令实在太多,又有很多各种各样的操作参数非常难以记忆,本文帮大家把常用的k8s指令归类进行了整理,以便辅助记忆。

    2024年02月21日
    浏览(33)
  • k8s 常用命令(四)

    [root@master ~]# kubectl delete deployment nginx -n kube-public   [root@master ~]# kubectl delete  svc  -n kube-public nginx-service    [root@master ~]# kubectl get endpoints   例如:查看 nginx 的版本号:   需求:修改这个运行中的 nginx 的版本号 [root@master ~]# kubectl set image deployment/nginx nginx=nginx:1.11   过程中,他

    2024年02月11日
    浏览(23)
  • k8s常用的命令

    下面是一些常用的Kubernetes(K8s)命令,以及它们的简要说明。这些命令可以帮助您管理和操作Kubernetes集群中的资源。 集群管理命令: kubectl cluster-info : 显示集群的基本信息。 kubectl config use-context context_name : 切换到指定的上下文。 kubectl get nodes : 列出集群中的节点。 kubectl

    2024年02月15日
    浏览(28)
  • k8s的常用命令

    Kubernetes是一种用于容器编排和管理的开源平台,以下是一些常用的Kubernetes命令: kubectl version:查看Kubernetes版本信息。 kubectl get:查看资源列表,例如 kubectl get pods 可以列出所有的Pods。 kubectl describe:查看资源的详细信息,例如 kubectl describe pod mypod 可以查看名称为 mypod 的

    2024年02月08日
    浏览(57)
  • k8s 常用命令(三)

    1 、 查看版本信息 : kubectl   version [root@master ~]# kubectl version [root@master ~]# kubectl version Client Version: version.Info{Major:\\\"1\\\", Minor:\\\"21\\\", GitVersion:\\\"v1.21.3\\\", GitCommit:\\\"ca643a4d1f7bfe34773c74f79527be4afd95bf39\\\", GitTreeState:\\\"clean\\\", BuildDate:\\\"2021-07-15T21:04:39Z\\\", GoVersion:\\\"go1.16.6\\\", Compiler:\\\"gc\\\", Platform:\\\"linux/amd64\\\"} S

    2024年02月11日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包