mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
fix: kotlin format
Removed an extra newline in the frontmatter
This commit is contained in:
1 file changed
+16
-100
+16
-100
@@ -3,26 +3,20 @@ title: Kubernetes
|
||||
date: 2023-01-09 10:26:55
|
||||
background: bg-[#416cde]
|
||||
tags:
|
||||
- config
|
||||
- format
|
||||
- config
|
||||
- format
|
||||
categories:
|
||||
- Programming
|
||||
- Programming
|
||||
intro: |
|
||||
This page contains a list of commonly used kubectl commands and flags.
|
||||
|
||||
This page contains a list of commonly used kubectl commands and flags.
|
||||
plugins:
|
||||
- copyCode
|
||||
- copyCode
|
||||
---
|
||||
|
||||
|
||||
Viewing and finding resources {.cols-2}
|
||||
---
|
||||
|
||||
|
||||
## Viewing and finding resources {.cols-2}
|
||||
|
||||
### Nodes
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get no # Display all node information
|
||||
kubectl get no -o wide # Show more information about all nodes
|
||||
@@ -36,11 +30,8 @@ kubectl top node [node_name] # Display node (CPU/memory/storage) usage
|
||||
|
||||
Resource name: nodes, abbreviation: no
|
||||
|
||||
|
||||
|
||||
### Pods
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get po # Display all container group information
|
||||
kubectl get po -o wide
|
||||
@@ -57,11 +48,8 @@ kubectl get pods --field-selector status.phase=Running
|
||||
|
||||
Resource name: pods, abbreviation: po
|
||||
|
||||
|
||||
|
||||
### Namespaces
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get ns
|
||||
kubectl get ns -o yaml
|
||||
@@ -70,24 +58,19 @@ kubectl describe ns
|
||||
|
||||
Resource name: namespaces, abbreviation: ns
|
||||
|
||||
|
||||
|
||||
### Deployments
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get deploy
|
||||
kubectl describe deploy
|
||||
kubectl get deploy -o wide
|
||||
kubectl get deploy -o yaml
|
||||
```
|
||||
|
||||
Resource name: deployments, abbreviation: deploy
|
||||
|
||||
|
||||
|
||||
### Services
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get svc
|
||||
kubectl describe svc
|
||||
@@ -95,26 +78,22 @@ kubectl get svc -o wide
|
||||
kubectl get svc -o yaml
|
||||
kubectl get svc --show-labels
|
||||
```
|
||||
|
||||
Resource name: services, abbreviation: svc
|
||||
|
||||
|
||||
|
||||
### Daemon Sets
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get ds
|
||||
kubectl describe ds --all-namespaces
|
||||
kubectl describe ds [daemonset_name] -n [namespace_name]
|
||||
kubectl get ds [ds_name] -n [ns_name] -o yaml
|
||||
```
|
||||
|
||||
Resource name: daemonsets, abbreviation: ds
|
||||
|
||||
|
||||
|
||||
### Events
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get events
|
||||
kubectl get events -n kube-system
|
||||
@@ -123,8 +102,6 @@ kubectl get events -w
|
||||
|
||||
Resource name: events, abbreviation: ev
|
||||
|
||||
|
||||
|
||||
### Logs
|
||||
|
||||
```bash
|
||||
@@ -135,24 +112,19 @@ kubectl logs -f -c [container_name] [pod_name]
|
||||
kubectl logs [pod_name] > pod.log
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Service Accounts
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get sa
|
||||
kubectl get sa -o yaml
|
||||
kubectl get serviceaccounts default -o yaml >./sa.yaml
|
||||
kubectl replace serviceaccount default -f ./sa.yaml
|
||||
```
|
||||
|
||||
Resource name: serviceaccounts, abbreviation: ev
|
||||
|
||||
|
||||
|
||||
### Replica Sets
|
||||
|
||||
|
||||
```bash
|
||||
kubectl get rs
|
||||
kubectl describe rs
|
||||
@@ -162,8 +134,6 @@ kubectl get rs -o yaml
|
||||
|
||||
Resource name: replicasets, abbreviation: rs
|
||||
|
||||
|
||||
|
||||
### Roles
|
||||
|
||||
```bash
|
||||
@@ -171,8 +141,6 @@ kubectl get roles --all-namespaces
|
||||
kubectl get roles --all-namespaces -o yaml
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Secrets
|
||||
|
||||
```bash
|
||||
@@ -181,8 +149,6 @@ kubectl get secrets --all-namespaces
|
||||
kubectl get secrets -o yaml
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Config maps
|
||||
|
||||
Resource name: configmaps, abbreviation: cm
|
||||
@@ -193,8 +159,6 @@ kubectl get cm --all-namespaces
|
||||
kubectl get cm --all-namespaces -o yaml
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Ingresses
|
||||
|
||||
Resource name: ingresses, abbreviation: ing
|
||||
@@ -204,8 +168,6 @@ kubectl get ing
|
||||
kubectl get ing --all-namespaces
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Persistent Volumes
|
||||
|
||||
Resource name: persistentvolumes, abbreviation: pv
|
||||
@@ -215,8 +177,6 @@ kubectl get pv
|
||||
kubectl describe pv
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Persistent volume declaration
|
||||
|
||||
Resource name: persistentvolumeclaims, abbreviation: pvc
|
||||
@@ -226,8 +186,6 @@ kubectl get pvc
|
||||
kubectl describe pvc
|
||||
```
|
||||
|
||||
|
||||
|
||||
### storage class
|
||||
|
||||
Resource name: storageclasses, Abbreviation: sc
|
||||
@@ -237,8 +195,6 @@ kubectl get sc
|
||||
kubectl get sc -o yaml
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Multiple resources
|
||||
|
||||
```bash
|
||||
@@ -248,10 +204,7 @@ kubectl get all
|
||||
kubectl get all --all-namespaces
|
||||
```
|
||||
|
||||
Updating resources
|
||||
---
|
||||
|
||||
|
||||
## Updating resources
|
||||
|
||||
### Taint
|
||||
|
||||
@@ -259,8 +212,6 @@ Updating resources
|
||||
kubectl taint [node_name] [taint_name]
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Label
|
||||
|
||||
```bash
|
||||
@@ -268,8 +219,6 @@ kubectl label [node_name] disktype=ssd
|
||||
kubectl label [pod_name] env=prod
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Maintain/Schedulable
|
||||
|
||||
```bash
|
||||
@@ -277,16 +226,12 @@ kubectl cordon [node_name] # node maintenance
|
||||
kubectl uncordon [node_name] # node is schedulable
|
||||
```
|
||||
|
||||
|
||||
|
||||
### clear
|
||||
|
||||
```bash
|
||||
kubectl drain [node_name] # empty the node
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Node/Pod {.row-span-2}
|
||||
|
||||
```bash
|
||||
@@ -296,8 +241,6 @@ kubectl edit node [node_name]
|
||||
kubectl edit pod [pod_name]
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Stateless/Namespaced {.row-span-2}
|
||||
|
||||
```bash
|
||||
@@ -309,8 +252,6 @@ kubectl delete ns
|
||||
kubectl edit ns [ns_name]
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Service
|
||||
|
||||
```bash
|
||||
@@ -318,16 +259,13 @@ kubectl edit svc [svc_name]
|
||||
kubectl delete svc [svc_name]
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Daemon set
|
||||
|
||||
```bash
|
||||
kubectl edit ds [ds_name] -n kube-system
|
||||
kubectl delete ds [ds_name]
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Service account
|
||||
|
||||
```bash
|
||||
@@ -335,8 +273,6 @@ kubectl edit sa [sa_name]
|
||||
kubectl delete sa [sa_name]
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Notes
|
||||
|
||||
```bash
|
||||
@@ -344,10 +280,7 @@ kubectl annotate po [pod_name] [annotation]
|
||||
kubectl annotateno [node_name]
|
||||
```
|
||||
|
||||
Create resources
|
||||
---
|
||||
|
||||
|
||||
## Create resources
|
||||
|
||||
### Create pod
|
||||
|
||||
@@ -359,34 +292,26 @@ kubectl run [pod_name] --generator=run-pod/v1 --image=nginx
|
||||
kubectl run [pod_name] --image=nginx --restart=Never
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Create Service
|
||||
|
||||
```bash
|
||||
kubectl create svc nodeport [svc_name] --tcp=8080:80
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Create a stateless application
|
||||
|
||||
```bash
|
||||
kubectl create -f [name_of_file]
|
||||
kubectl create -f [name_of_file]
|
||||
kubectl apply -f [name_of_file]
|
||||
kubectl create deploy [deploy_name] --image=nginx
|
||||
```
|
||||
|
||||
|
||||
|
||||
### interaction
|
||||
|
||||
```bash
|
||||
kubectl run [pod_name] --image=busybox --rm -it --restart=Never --sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Output YAML
|
||||
|
||||
```bash
|
||||
@@ -394,8 +319,6 @@ kubectl create deploy [deploy_name] --image=nginx --dry-run -o yaml > deploy.yam
|
||||
kubectl get po [pod_name] -o yaml --export > pod.yaml
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Help
|
||||
|
||||
```bash
|
||||
@@ -405,11 +328,7 @@ kubectl run -h
|
||||
kubectl explain deploy.spec
|
||||
```
|
||||
|
||||
|
||||
Miscellaneous
|
||||
---
|
||||
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
### APIs
|
||||
|
||||
@@ -417,8 +336,6 @@ Miscellaneous
|
||||
kubectl get --raw /apis/metrics.k8s.io/
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Information
|
||||
|
||||
```bash
|
||||
@@ -427,7 +344,6 @@ kubectl cluster-info
|
||||
kubectl get componentstatus
|
||||
```
|
||||
|
||||
Also See
|
||||
---
|
||||
## Also See
|
||||
|
||||
- [Kubernetes Official Documentation](https://kubernetes.io/zh-cn/docs/reference/kubectl/) _(kubernetes.io)_
|
||||
Reference in new issue
Block a user