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).

k8s 操作命令(合集List)的更多相关文章

  1. linux基础操作命令合集(一)

    linux基础操作命令合集(一) 目录 linux基础操作命令合集(一) 一.命令行提示符 二.切换用户 三.主机名称命令 3.1.临时设置主机名 3.2.永久设置主机名 四.查看系统版本 五.网卡相 ...

  2. Redis操作命令合集

    目录 一.客户端命令 二.sql命令 一.客户端命令 #读取配置文件启动 redis-server redis.conf #关闭 Redis,Redis服务器将断开与客户端链接,产生持久化文件,平滑关 ...

  3. Git基本操作命令合集

    平时自己敲敲代码,使用Git命令也渐渐多了起来.使用起来的确很方便,今天来分享下Git基本概念和本地代码提交到github上的过程,很简单的,多操作几次就会了. Git定义 Git 是一个开源的分布式 ...

  4. Timesten 日常管理命令合集

    Timesten 日常管理命令合集 以下所有操作都是基于TT  11 版,早前版本本人没用过,命令是否适用我不清楚啊! 各类服务管理 一.TT的启停  停服务:  1.停止复制与cache 进程:  ...

  5. Linux常用命令合集

    常用命令合集 命令选项和参数 Linux中的命令格式为:command [options] [arguments]  //中括号表示可选的,即有些命令不需要选项也不需要参数,但有的命令在运行时需要多个 ...

  6. SQL Server技术内幕笔记合集

    SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...

  7. 【Android】开发中个人遇到和使用过的值得分享的资源合集

    Android-Classical-OpenSource Android开发中 个人遇到和使用过的值得分享的资源合集 Trinea的OpenProject 强烈推荐的Android 开源项目分类汇总, ...

  8. [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集

    虽然忙,有些事还是要抽时间做; Erlang Resources 小站 2014年1月~6月资讯合集,方便检索.      小站地址: http://site.douban.com/204209/   ...

  9. [Erlang 0114] Erlang Resources 小站 2013年7月~12月资讯合集

    Erlang Resources 小站 2013年7月~12月资讯合集,方便检索.     附 2013上半年盘点: Erlang Resources 小站 2013年1月~6月资讯合集    小站地 ...

  10. SQL用法操作合集

    SQL用法操作合集   一.表的创建 1.创建表 格式: 1 CREATE TABLE 表名 2 (列名 数据类型(宽度)[DEFAULT 表达式][COLUMN CONSTRAINT], 3 ... ...

随机推荐

  1. yolov5 损失函数代码详解

    前言 模型的损失计算包括3个方面,分别是: 定位损失 分类损失 置信度损失 损失的计算公式如下: 损失计算的代码流程也是按照这三大块来计算的.本篇主要讲解yolov5中损失计算的实现,包括损失的逻辑实 ...

  2. ProgressBar 进度控件

    在 VB.NET 中,你可以使用 ProgressBar 控件或者自定义的进度提示方法来实现这个功能.以下是一个示例代码,展示如何使用 ProgressBar 控件来显示导入情况: ' 创建一个 Pr ...

  3. AT_abc178_d 题解

    洛谷链接&Atcoder 链接 本篇题解为此题较简单做法及较少码量,并且码风优良,请放心阅读. 题目简述 给定一个正整数 \(S\),问有多少个数满足以下条件: 序列中必须为 \(\ge 3\ ...

  4. pytest批量执行多个测试文件(批量执行一个文件夹下的所有测试用例)

    图片 代码 #!/usr/bin/env python # @File : test_runall.py import pytest import os # path = os.path.dirnam ...

  5. java面试一日一题:rabbitMQ如何保证消息不丢失

    问题:请讲下rabbitMQ如何保证消息不丢失 分析:该问题属于概念题,同时也是一个设计方面的题,牵扯到部分设计层面的东西: 回答要点: 主要从以下几点去考虑, 1.rabbitMQ在保证消息不丢失方 ...

  6. 如何对jar包修改并重新发布在本机

    本人苦于jieba不能如何识别伊利丹·怒风,召唤者坎西恩这种名字,对jieba-analysis进行了解包和打包 步骤1:找到对应jar 步骤2:在cmd中输入jar -xvf xxx.jar解压包, ...

  7. MindSpore 建立神经网络

    代码原地址: https://www.mindspore.cn/tutorial/zh-CN/r1.2/model.html 建立神经网络: import mindspore.nn as nn cla ...

  8. 祝贺小鹏汽车Gallardot同学成为Apache DolphinScheduler Committer!

    社区迎来新committer!这次是来自小鹏汽车的Gallardot,看看他与Apache DolphinScheduler社区的故事吧. 对话社区 Q1:您为Apache DolphinSchedu ...

  9. AWG(American wire gauge)美国线规

    AWG(American wire gauge)美国线规,是一种区分导线直径的标准,又被称为 Brown & Sharpe线规.这种标准化线规系统于1857年起在美国开始使用.AWG前面的数值 ...

  10. 轻松易懂,一文告诉你什么是http协议?

    阅读本文之前,请详细阅读以下几篇文章: <一文包你学会网络数据抓包> <教你如何抓取网络中的数据包!黑客必备技能> 一.什么是http? Http协议即超文本传送协议 (HTT ...