kubectl-basics
Solidkubectl 基础操作与常用命令
AI & Automation 1 stars
0 forks Updated yesterday Apache-2.0
Install
Quality Score: 79/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# kubectl 基础操作
## 概述
kubectl 是 Kubernetes 的命令行工具,用于与集群进行交互。本 skill 涵盖日常运维中最常用的命令。
## 集群信息
```bash
# 集群信息
kubectl cluster-info
kubectl version
# 节点信息
kubectl get nodes
kubectl describe node <node-name>
# 上下文切换
kubectl config get-contexts
kubectl config use-context <context-name>
```
## 资源查看
### 常用资源
```bash
# Pod
kubectl get pods
kubectl get pods -o wide
kubectl get pods -A # 所有命名空间
# Deployment
kubectl get deployments
kubectl get deploy -o yaml
# Service
kubectl get services
kubectl get svc
# 所有资源
kubectl get all
kubectl get all -n <namespace>
```
### 输出格式
```bash
kubectl get pods -o wide # 详细信息
kubectl get pods -o yaml # YAML 格式
kubectl get pods -o json # JSON 格式
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
```
## 资源操作
### 创建与删除
```bash
# 从文件创建
kubectl apply -f manifest.yaml
kubectl create -f manifest.yaml
# 删除资源
kubectl delete -f manifest.yaml
kubectl delete pod <pod-name>
kubectl delete pod <pod-name> --force --grace-period=0
```
### 编辑与更新
```bash
# 编辑资源
kubectl edit deployment <name>
# 打补丁
kubectl patch deployment <name> -p '{"spec":{"replicas":3}}'
# 扩缩容
kubectl scale deployment <name> --replicas=5
```
## Pod 调试
```bash
# 查看日志
kubectl logs <pod-name>
kubectl logs <pod-name> -c <container>
kubectl logs <pod-name> -f # 实时跟踪
kubectl logs <pod-name> --previous # 上一个容器
# 进入容器
kubectl exec -it <pod-name> -- /bin/bash
kubectl exec -it <pod-name> -c <container> -- sh
#...
Details
- Author
- ryukyagamilight
- Repository
- ryukyagamilight/terminal-skills
- Created
- 5 months ago
- Last Updated
- yesterday
- Language
- N/A
- License
- Apache-2.0
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Solid
deployment
Kubernetes Deployment 管理
1 Updated yesterday
ryukyagamilight DevOps & Infrastructure Listed
managing-kubernetes
Manages Kubernetes clusters via kubectl. Supports pod/deployment/service management, log viewing, port-forwarding, and debugging. Use for "k8s", "kubectl", "파드", cluster management tasks.
1 Updated 5 days ago
Open330 AI & Automation Solid
container-ops
Docker 容器操作与管理
1 Updated yesterday
ryukyagamilight