What is a resource?

All the content in K8s is abstracted as resources, and after resources are instantiated, they are called objects.

List of resource types

  • Workload

    Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, CronJob (ReplicationController is deprecated in v1.11)

  • Service Discovery and Load Balancing

    Service, Ingress …

  • Storage

    Volume, CSI

  • Configuration

    ConfigMap, Secret, DownwardAPI

  • Cluster

    Namespace, Node, Role, ClusterRole, RoleBinding, ClusterRoleBinding

  • Metadata

    HPA, PodTemplate, LimitRange

List of resources

What is a resource manifest?

In K8S, we generally use yaml format files to create pods that meet our expected expectations, and such yaml files we generally call resource lists.

Resource list format

apiVersion: group/apiversion  

apiVersion: If no group name is given, then the default is croe, you can use kubectl api-versions to get all the apiVersion information on the current k8s version (each version may be different), or you can use kubectl explain resource name|grep VERSION to get the apiversion of the corresponding resource kind: resource category metadata: resource metadata spec: expected state (disired state) status: current state, this field is maintained by kubernetes itself and cannot be defined by the user

View list format

Take pod resources as an example, you can use the following command if you want to view the resource manifest format of pod resources.

kubectl explain pod

You can only see the first level configuration with the above command. If you want to see the second level, such as metadata and spec, you can use the following command.

kubectl explain pod.metadata
kubectl explain pod.spec


What is Namespace?

Namespace, also known as namespace, is a very important resource in the kubernetes system. Its main role is to enable resource isolation for multiple environments or multi-tenant resource isolation.


By default, all Pods in a kubernetes cluster are accessible to each other. However, in practice, you may not want two Pods to have access to each other, so you can divide them into different namespaces. kubernetes can form logical “groups” by assigning resources inside the cluster to different namespaces, so that the resources of different groups can be used and managed in isolation. Through the authorization mechanism of kubernetes, different namespaces can be given to different tenants for management, thus achieving multi-tenant resource isolation. At this point, you can also combine kubernetes’ resource quota mechanism to limit the resources that different tenants can occupy, such as CPU usage, memory usage, etc., to achieve the management of resources available to tenants.


  • List all namespaces

    kubectl get ns
  • Create namespace

    kubectl create ns dev
  • Delete namespace

    kubectl delete ns dev
  • Resource List

    apiVersion: v1
    kind: Namespace
    name: dev

    create: kubectl create -f ns-dev.yaml

    delete: kubectl delete -f ns-dev.yaml

Resource Management

Resource management methods

  • Command-based object management: use commands directly to manipulate kubernetes resources
  • Command-based object configuration: manipulate kubernetes resources with command configuration and configuration files
  • Declarative object configuration: manipulate kubernetes resources through apply command and configuration file

Command-based object management


The kubectl command is the command line tool for kubernetes centralized management, which enables the management of the cluster itself and the installation and deployment of containerized applications on the cluster. The command syntax is as follows:

kubectl [command] [type] [name] [flags]

comand: Specify the operation to be performed on the resource, such as create, get, delete type: specify the type of resource, such as deployment, pod, service name: specify the name of the resource, the name is case-sensitive flags: specifies additional optional parameters


Basic commands
command command role
create create a resource
edit edit a resource
get Get a resource
patch update a resource
delete delete a resource
explain display a resource document
Run Debug
command command role
run runs a specified image in the cluster
expose expose a resource as a Service
describe displays information about the resource’s internals
logs export the container’s logs in the Pod
attach to a running container
exec execute a command in the container
cp Copy files between Pods and inside and outside
rollout manage the release of resources
scale expands (scales) the number of Pods
autoscale Automatically adjusts the number of Pods
Other Commands
Commands Command role
apply create or update a resource by file
label Update the label on a resource
cluster-info displays cluster information
version displays the current version of the Client and Server


Resource resource type, not listed here, as already mentioned above.

Command-based object configuration

Command-based object configuration is the use of commands in conjunction with a resource list

Once the resource manifest is created, use the following command

Create resources: kubectl create -f resource list View resources: kubectl get -f resource list delete resources: kubectl delete -f resource list

Declarative Object Configuration

Declarative object configuration is very similar to imperative object configuration, but it has only one command: apply.

The difference with imperative object configuration is that imperative is used to create and delete, while declarative is used to modify. When the resource list is modified, you can use the following command to update the resources.

Update resources: kubectl apply -f resource list