主頁 >  其他 > k8s 操作命令(合集List)

k8s 操作命令(合集List)

2023-07-05 08:25:11 其他

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.uj5u.com/qita/556602.html

標籤:其他

上一篇:Nftables堆疊溢位漏洞(CVE-2022-1015)復現

下一篇:返回列表

標籤雲
其他(162075) Python(38266) JavaScript(25522) Java(18289) C(15238) 區塊鏈(8275) C#(7972) AI(7469) 爪哇(7425) MySQL(7285) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5876) 数组(5741) R(5409) Linux(5347) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4610) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2438) ASP.NET(2404) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) HtmlCss(1987) .NET技术(1985) 功能(1967) Web開發(1951) C++(1942) python-3.x(1918) 弹簧靴(1913) xml(1889) PostgreSQL(1882) .NETCore(1863) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • k8s 操作命令(合集List)

    ### k8s 操作命令 合集List ### 一、K8S最常用命令如下: 1、獲取pod資訊:kubectl get pod 2、查看指定pod的日志資訊:kubectl logs -f --tail(最后多少行) 500 podName(pod名) 3、查看pod的描述資訊:kubectl de ......

    uj5u.com 2023-07-05 08:25:11 more
  • Nftables堆疊溢位漏洞(CVE-2022-1015)復現

    Nftables 是一個基于內核的包過濾框架,用于 Linux作業系統中的網路安全和防火墻功能。nftables的設計目標是提供一種更簡單、更靈活和更高效的方式來管理網路資料包的流量。 ......

    uj5u.com 2023-07-05 08:24:43 more
  • 分布式事務的幾種實作方式

    ## 基礎理論 ### CAP理論 一致性(Consistency) :在分布式系統中所有的資料備份,在同一時刻都保持一致狀態,如無法保證狀態一致,直接回傳錯誤; 可用性(Availability):在集群中一部分節點故障,也能保證客戶端訪問系統并得到正確回應,允許一定時間內資料狀態不一致; 磁區容 ......

    uj5u.com 2023-07-05 08:23:59 more
  • 把langchain跑起來的3個方法

    使用LangChain開發LLM應用時,需要機器進行GLM部署,好多同學第一步就被勸退了,那么如何繞過這個步驟先學習LLM模型的應用,對Langchain進行快速上手?本片講解3個把LangChain跑起來的方法,如有錯誤歡迎糾正。 ......

    uj5u.com 2023-07-05 08:23:55 more
  • python介面自動化封裝匯出excel方法和讀寫excel資料

    一、首先需要思考,我們在頁面匯出excel,用python匯出如何寫入檔案的 封裝前需要確認python匯出excel介面回傳的是一個什么樣的資料型別 如下:我們先看下不對回傳結果做處理,直接接收資料型別是一個物件,無法獲取回傳值 ![image.png](https://p3-juejin.byt ......

    uj5u.com 2023-07-05 08:23:50 more
  • 我做了10年的測驗,由衷的建議年輕人別入這行了...

    兩天前,有個做功能測驗7年的同事被裁員了。這位老哥已經做到了團隊中的骨干了,人又踏實,結果沒想到剛剛踏入互聯網“老齡化”大關,就被公司給無情優化了。 現在他想找同型別的作業,薪資也一直被壓,考慮轉行轉型的話,上升空間又窄。昨天還在指點江山,今天已經過的緊緊巴巴,實在令人唏噓。 關鍵的是,這不是第一個 ......

    uj5u.com 2023-07-05 08:23:42 more
  • 華為云河圖KooMap 共筑數字孿生底座 共建產業標桿

    摘譯:7月7日至9日,華為開發者大會2023(Cloud)將在東莞溪村盛大舉行,由華為云河圖KooMap帶來的關于數字孿生主題的技術分論壇、圓桌閉門會和精彩成果展示 7月7日至9日,華為開發者大會2023(Cloud)將在東莞溪村盛大舉行。作為全球開發者期待的行業盛會,本屆大會將在全球40+會場舉辦 ......

    uj5u.com 2023-07-05 08:23:30 more
  • 北斗衛星時鐘同步服務器(衛星授時服務)天線安裝意見

    北斗衛星時鐘同步服務器(衛星授時服務)天線安裝意見 北斗衛星時鐘同步服務器(衛星授時服務)天線安裝意見 京準電子科技官微——ahjzsz 衛星天線介紹 一、電氣特性 1、線的長度:30米 2、線的規格:SYV-50-3 3、規格:BNC、TNC、N型接頭 4、作業頻率、頻寬 :1575.42MHz、 ......

    uj5u.com 2023-07-05 08:23:20 more
  • 《山月記》—— 中島敦

    我深怕自己本非美玉,故而不敢加以刻苦琢磨,卻又半信自己是塊美玉,故又不肯庸庸碌碌,與瓦礫為伍。 于是我漸漸地脫離凡塵,疏遠世人,結果便是一任憤懣與羞恨日益助長內心那怯弱的自尊心。 其實,任何人都是馴獸師,而那野獸,無非就是各人的性情而已。 于我而言,這種妄自尊大的羞恥心就是野獸,就是猛虎。 它毀了我 ......

    uj5u.com 2023-07-05 08:23:11 more
  • 詳解共識演算法的Raft演算法模擬數

    摘要:Raft演算法是一種分布式共識演算法,用于解決分布式系統中的一致性問題。 本文分享自華為云社區《共識演算法之Raft演算法模擬數》,作者: TiAmoZhang 。 01、Leader選舉 存在A、B、C三個成員組成的Raft集群,剛啟動時,每個成員都處于Follower狀態,其中,成員A心跳超時為1 ......

    uj5u.com 2023-07-05 08:16:29 more