Welcome to Firefly
English
Firefly Docsss
Last Updated: 2026-09-29 15:48:06

Common Commands

Cluster Information

CommandPurpose
kubectl cluster-infoShow the cluster API Server and core component information
kubectl get nodesShow the node list, status, roles, and versions
kubectl get nodes -o wideShow node IP addresses, operating systems, container runtimes, and other details
kubectl describe node <node name>Show node resources, labels, taints, and events

Pod Management

CommandPurpose
kubectl get podsShow the Pods in the current namespace
kubectl get pods -n <namespace>Show the Pods in the specified namespace
kubectl get pods -AShow the Pods in all namespaces
kubectl get pods -o wideShow the Pod IP addresses and the nodes they run on
kubectl describe pod <pod name>Show Pod details, events, and container configuration
kubectl logs <pod name>Show the Pod logs
kubectl logs <pod name> -fFollow the Pod logs
kubectl logs <pod name> -c <container name>Show the logs of the specified container
kubectl delete pod <pod name>Delete the specified Pod; Pods managed by a Deployment are recreated automatically

Service Management

A Service provides a stable entry point for a group of Pods. A Pod IP may change after the Pod is created, deleted, or restarted, so other applications should not depend on Pod IPs directly. A Service finds the matching Pods through a label selector and forwards requests to the available Pods.

In short:

  • Pod: the container instance that actually runs the application.
  • Service: provides a stable name and address for the Pods.
  • Client: accesses the application through the Service without caring about the individual Pod IPs.

The common Service types are:

TypeAccess scopeTypical use
ClusterIPInside the cluster onlyService-to-service calls; this is the default type
NodePortReachable from outside through a node IP and portTesting or exposing a service in a simple way
LoadBalancerReachable through a load balancerCloud environments or clusters with a load balancer configured

In the current K3s environment, a NodePort can expose a web service outside the cluster. For example, once a Service maps port 80 of a container to a port on the node, the application is reachable at http://<node IP>:<NodePort>.

CommandPurpose
kubectl get svcShow the Services in the current namespace
kubectl get svc -n <namespace>Show the Services in the specified namespace
kubectl get svc -AShow the Services in all namespaces
kubectl describe svc <service name>Show Service port mappings and backend Pods
kubectl expose deployment <deployment name> --type=NodePort --port=80 --target-port=80 --name=<service name>Create a NodePort Service from a Deployment

Deployment Management

A Deployment manages applications that need to run continuously, such as web services, API services, and background services. It maintains the configured number of Pod replicas through a ReplicaSet and supports rolling updates, automatic failure recovery, and replica scaling.

Typical use cases:

  • Long-running stateless services
  • Applications that need several Pod replicas
  • Applications that need rolling updates or fast rollbacks
CommandPurpose
kubectl get deployShow the Deployments in the current namespace
kubectl get deploy -n <namespace>Show the Deployments in the specified namespace
kubectl apply -f <YAML file>Create or update resources from a YAML file
kubectl delete -f <YAML file>Delete resources defined in a YAML file
kubectl scale deploy <deployment name> --replicas=<count>Adjust the number of Pod replicas of a Deployment
kubectl rollout status deploy/<deployment name>Show the update status of a Deployment
kubectl rollout restart deploy/<deployment name>Restart the Pods managed by a Deployment

Job Management

A Job runs one-off or finite tasks, such as data processing, initialization, and batch jobs. A Job creates Pods and keeps retrying until the task completes successfully or the configured retry count is reached.

Typical use cases:

  • One-off data processing
  • Database initialization or migration
  • Batch file processing
  • Cluster or application initialization
CommandPurpose
kubectl create job <job name> --image=<image name>Create a one-off Job
kubectl get jobsShow the Jobs in the current namespace
kubectl get jobs -AShow the Jobs in all namespaces
kubectl describe job <job name>Show Job status, Pods, and events
kubectl wait --for=condition=complete job/<job name> --timeout=180sWait for the Job to complete
kubectl logs job/<job name>Show the logs of the Pod created by the Job
kubectl delete job <job name>Delete the Job and its Pods
kubectl apply -f <job YAML file>Create or update a Job from a YAML file

CronJob Management

A CronJob creates Jobs periodically on a schedule, for example for backups, log cleanup, and recurring data synchronization. Each run creates a Job, and the Job creates and runs the Pod.

Typical use cases:

  • Scheduled backups
  • Cleaning up temporary files or logs on a schedule
  • Recurring data synchronization
  • Generating reports on a schedule

A CronJob sets its execution time with a standard Cron expression; for example, */5 * * * * means "run every 5 minutes".

CommandPurpose
kubectl create cronjob <cronjob name> --image=<image name> --schedule="*/5 * * * *"Create a CronJob that runs on a schedule
kubectl get cronjobsShow the CronJobs in the current namespace
kubectl get cronjobs -AShow the CronJobs in all namespaces
kubectl describe cronjob <cronjob name>Show the schedule, status, and events of a CronJob
kubectl get jobs --sort-by=.metadata.creationTimestampShow the Jobs created by a CronJob
kubectl get pods --sort-by=.metadata.creationTimestampShow the Pods created by a CronJob
kubectl patch cronjob <cronjob name> -p '{"spec":{"suspend":true}}'Suspend further scheduling of the CronJob
kubectl patch cronjob <cronjob name> -p '{"spec":{"suspend":false}}'Resume the schedule of the CronJob
kubectl delete cronjob <cronjob name>Delete the CronJob and its future runs
kubectl apply -f <cronjob YAML file>Create or update a CronJob from a YAML file

Namespaces and Configuration

A namespace divides a K3s cluster into isolated resource scopes. Create separate namespaces for projects, teams, or environments, for example dev, test, and prod, to avoid name conflicts between applications and to simplify permission and resource management.

ConfigMaps and Secrets store the configuration an application needs at runtime:

  • ConfigMap: stores ordinary configuration such as environment variables, configuration files, and service addresses.
  • Secret: stores sensitive information such as passwords, tokens, and certificates. A Secret is not a complete encryption solution, so restrict access and avoid committing sensitive content to a code repository.

When creating an application, specify the namespace with metadata.namespace in the manifest. When running commands, specify the target namespace with -n <namespace>. Without a namespace, a command applies to the current namespace, usually default.

CommandPurpose
kubectl get nsShow all namespaces
kubectl create ns <namespace name>Create a namespace
kubectl get configmapShow the ConfigMaps in the current namespace
kubectl get secretShow the Secrets in the current namespace
kubectl get events -A --sort-by=.lastTimestampShow the events of all namespaces in chronological order

Resources and Troubleshooting

CommandPurpose
kubectl top nodesShow the CPU and memory usage of the nodes
kubectl top pods -AShow the CPU and memory usage of all Pods
kubectl get pods -A -o wideShow the status, IP, and node of all Pods
kubectl describe pod <pod name> -n <namespace>Show Pod details and abnormal events

On this page