1. What are kubernetes resources?
All content in kubernetes is abstracted as resources, and resources are called objects after instantiation.
2. Classification of kubernetes resources
Kubernetes resources mainly include namespace-level resources, cluster-level resources, and metadata-based resources.
2.1 Namespace-level resources
It only takes effect for this namespace. A namespace is an isolation level. Resources in different namespaces are isolated from each other. For example, Alibaba Cloud, our commonly used public cloud platform, both Company A and Company B purchased on Alibaba Cloud. Although the cloud server resources are on the same cloud platform, it is also possible that the cloud hosts of the two companies are in the same physical computer room. But A cannot view and use the server of Company B, and B cannot view A's either.
2.1.1 Namespace-level resources
2.1.1.1 Workload resources
Resource Name | concept |
---|---|
Pod | Pod is the smallest scheduling unit in kubernetes. Containers are included in Pods. A Pod has a pause container and several business containers, and a Pod is a single container. In short, a Pod is a collection of containers. |
ReplicaSet | ReplicaSet is a replica controller in the kuberntees cluster, its main function is to control and manage Pods, usually used in conjunction with deployment |
Deployment | An object used to deploy applications, providing a declarative definition method for Pod and ReplicaSet, mainly used to manage applications |
Daenon Set | The daemon set is similar to the daemon process, ensuring that a pod is deployed on each node |
Job | Responsible for batch processing short-lived one-time tasks, executed only once, and ensuring that one or more Pods processed successfully end. |
CronJob | Responsible for timing tasks, running specified tasks in specified time periods. |
StatefulSet | StatefulSet is to solve the problems of stateful services, such as stable persistent storage, stable network identification, orderly deployment, and orderly expansion. orderly shrink, orderly delete |
2.1.1.2 Service discovery and load balancing resources
Resource Name | concept |
---|---|
Service | It is an abstract concept that defines a logical collection of multiple pods for a service and a strategy for accessing pods. Generally, a service is called a microservice. |
Ingress | is a way to expose services to clients outside of the kubernetes cluster. |
2.1.1.3 Configuration and storage resources
Resource Name | concept |
---|---|
Volume | It is an object abstracted by kubernetes to solve the problem of file storage when the Pod container is running and the problem of file directory sharing between multiple containers. |
CSI | Container storage interface, which can expand various third-party storage volumes |
2.1.1.4 Special types of resources and storage volume resources
Resource Name | concept |
---|---|
ConfigMap | configuration management component, . The configuration can be passed in the form of key-value pairs, which is usually used to save configuration information that does not need to be encrypted |
Secret | An object that contains a small amount of sensitive information such as a password, token, or key. |
DownwardAPI | Used to output information from the external environment to the container. |
2.2 Cluster-level resources
A cluster may have multiple namespaces, and cluster-level resources manage namespace-level resources. Cluster-level resources, regardless of which namespace defines cluster-level resources, can be seen under other namespaces. When defining There is no need to specify a namespace, it is visible, callable, and globally unique across the entire cluster.
2.2.1 What are the cluster-level resources?
Resource Name | concept |
---|---|
Namespace | namespace |
Node | cluster node |
Role | Role |
ClusterRole | cluster role |
ClusterRoleBinding | Cluster role binding |
2.3 Metadata resources
Provide us with an indicator. For example, HPA can scale the pod horizontally by defining the indicator of cpu or memory usage. This is a typical metadata resource
Resource Name | concept |
---|---|
HPA | The full name Horizontal Pod Autoscaler is a resource object that can dynamically scale pods in statefulset and deployment according to certain indicators |
PodTemplate | pod template |
LimitRange | resource constraints |
What is a resource manifest?
In kubernetes, files in yaml format are generally used to create resource objects such as pods, deployments, and services that we need. Such yaml files are generally called resource lists.
Example pod manifest file
Obtained by kubectl explain pod
, the pod resource list uses the help
to write the pod resource list file
#cat demo-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
labels:
app: pod-demo
spec:
containers:
- name: pod-demo
image: registry.cn-hangzhou.aliyuncs.com/my_app_repo/nginx:v1
Deployment resource manifest example file
#cat deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ngx-demo
labels:
app: ngx-dep-demo
spec:
replicas: 3
selector:
matchLabels:
app: ngx-dep-demo
template:
metadata:
labels:
app: ngx-dep-demo
spec:
containers:
- name: ngx-demo
image: registry.cn-hangzhou.aliyuncs.com/my_app_repo/nginx:v1
ports:
- containerPort: 80
Service resource manifest sample file
#cat deployment-svc.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: ngx-dep-test
spec:
replicas: 3
selector:
matchLabels:
app: ngx-dep-test
template:
metadata:
labels:
app: ngx-dep-test
spec:
containers:
- name: ngx-dep-test
image: registry.cn-hangzhou.aliyuncs.com/my_app_repo/nginx:v1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
labels:
app: ngx-dep-test
name: ngx-dep-test-svc
spec:
type: ClusterIP
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: ngx-dep-test
Create and view resources created using resource manifests
Use kubectl create或apply -f xxfilename
to create resources
example
#kubectl apply -f pod.yaml
deployment.apps/ngx-dep-test created
service/ngx-dep-test-svc created
Use kubectl get xxxx
(if the resource type name does not specify a namespace, the resources under the default namespace will be obtained by default)
delete resource
kubectl delete -f xxxfilename
example
#kubectl delete -f pod.yaml
deployment.apps "ngx-dep-test" deleted
service "ngx-dep-test-svc" deleted