当前位置:网站首页>Kubernetes resource list: how to create resources?
Kubernetes resource list: how to create resources?
2022-07-24 20:34:00 【Hua Weiyun】
stay Kubernetes The content of all operations in , We all call it “ Resource objects ”, By API Server be based on HTTP/HTTPS Receive and respond to the client's operation request , It's a kind of Restful Style interface , Abstract all kinds of components and operation contents into standard REST resources , Such as Namespace、Pod etc. , The operation contents are as follows JSON or yml Format data for operation .
This article is about Kubernetes The most important section in —— Resource list , We want to Kubernetes Deployment in China Pod、Service Equal resource object , All of them need to be deployed by means of resource list , Whether by command kubectl , Or the visual console , The definition of resource list is indispensable , This article focuses on how to define a resource list 、 How to create and use .
1、 Resource classification
Classify resources according to their functions ,Kubernetes Resource objects can be divided into :
- The workload (Workload):Pod、ReplicaSet、Deployment、StatefulSet、DaemonSet、Job、CronJob.
- Discovery and load balancing (Discovery & LB):Service 、Ingress.
- Configuration and storage (Config & Storage): Volume( Storage volume )、CSI( Container storage interface , Can expand a variety of third-party storage volumes ).
- colony (Cluster) :Namespace、Node、Role、ClusterRole、RoleBinding( Character binding )、ClusterRoleBinding( Cluster role binding ).
- Metadata (Metadata) :HPA、PodTemplate(Pod Templates , Used to let the controller create Pod The template used when )、LimitRange( Used to define hardware resource constraints ).
An application usually needs the support of multiple resources , for example , Use Deployment Examples of resource management applications (Pod)、 Use ConfigMap Resource saving application configuration 、 Use Service or Ingress Resource exposure Services 、 Use Volume Resources provide external storage, etc .
2. Resource list
Resource list , It's equivalent to a play , Can tell us how to do each step ,Kubernetes Received such a script , It can be executed according to this script , To meet our expectations .
stay Kubernetes in , Generally, resources are created by defining resource lists . In general use yaml File format to create resources that meet our expectations , In this way yaml We call the document ** Resource list ** .( It can also be defined as json Format )
Such as , Create a Pod resources :
apiVersion: v1kind: Podmetadata: name: vue-frontend namespace: test labels: app: vue-frontendspec: containers: - name: vue-frontend image: xcbeyond/vue-frontend:latest ports: - name: port containerPort: 80 hostPort: 8080Next , With Pod Resource definition as an example to expand the detailed description of the resource list .
2.1 Resource list definition
yaml Format Pod The complete contents of the resource list definition file are as follows :
apiVersion: v1kind: Pod # Resource categories metadata: # Resource metadata name: string namespace: string labels: - name: string annotations: - name: stringspec: # The state of resource expectations containers: # List of containers - name: string # Container name , The following attributes belong to the definition or constraint of the container image: string imagePullPolicy: [Always|Never|IfNotPresent] command: [string] args: [string] workingDir: string volumeMounts: - name: string mountPath: string readOnly: boolean ports: - name: string containerPort: int hostPort: int protocol: string env: - name: string value: string resources: limits: cpu: string memory: string requests: cpu: string memory: string livenssProbe: exec: command: [string] httpGet: path: string port: number host: string scheme: string httpHeaders: - name: string value: string tcpSocket: port: number initialDelaySeconds: 0 timeoutSeconds: 0 periodSeconds: 0 successThreshold: 0 failureThreshold: 0……A detailed description of each attribute is shown in the following table :
( Required attributes , Must exist , Otherwise, the creation fails .)




The above list of common properties , If you want to see all properties , You can use commands `kubectl explain pod`:
[[email protected] ~]$ kubectl explain podKIND: PodVERSION: v1DESCRIPTION: Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.FIELDS: apiVersion <string> APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources kind <string> Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds metadata <Object> Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata spec <Object> Specification of the desired behavior of the pod. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status status <Object> Most recently observed status of the pod. This data may not be up to date. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-statusSee the property description , Use the following command , Such as : see pod.spec.containers
[[email protected] ~]$ kubectl explain pod.spec.containersKIND: PodVERSION: v1RESOURCE: containers <[]Object>DESCRIPTION: List of containers belonging to the pod. Containers cannot currently be added or removed. There must be at least one container in a Pod. Cannot be updated. A single application container that you want to run within a pod.FIELDS: args <[]string> Arguments to the entrypoint. The docker image's CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell command <[]string> Entrypoint array. Not executed within a shell. The docker image's ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell……2.2 Example
In namespace test in , Define a name frontend Of Pod.
(1) Define the namespace
In order to facilitate later testing , To specify a new namespace test.( If the namespace test Already exists , There is no need to build )
Namespace test List of resources file test-namespace.yaml as follows :
apiVersion: v1kind: Namespacemetadata: name: test perform kubectl create Command to create the Namespace:
[[email protected] ~]$ kubectl create -f test-namespace.yaml namespace/test created(2) Definition Pod
Define a name frontend Of Pod, It's made up of a container , Resource list file frontend-pod.yaml as follows :
apiVersion: v1kind: Podmetadata: name: frontend namespace: test labels: app: frontendspec: containers: - name: frontend image: xcbeyond/vue-frontend:latest ports: - name: port containerPort: 80 hostPort: 8080 perform kubectl create Command to create the Pod:
[[email protected] ~]$ kubectl create -f frontend-pod.yaml pod/frontend created Through the command kubectl get pods -n see , establish Pod The state of :
[[email protected] ~]$ kubectl get pods -n testNAME READY STATUS RESTARTS AGEfrontend 1/1 Runing 0 79s边栏推荐
- A new UI testing method: visual perception test
- Open source demo | release of open source example of arcall applet
- Processing of null value of Oracle notes
- [training Day10] point [enumeration] [bidirectional linked list]
- Huawei set up login with account and password
- Two methods of how to export asynchronous data
- 2022 chemical automation control instrument test question simulation test platform operation
- The maximum number of expressions in ora-01795 list is 1000
- Selenium is detected as a crawler. How to shield and bypass it
- Leetcode 1928. minimum cost of reaching the destination within the specified time
猜你喜欢

Understand the domestic open source Magnolia license series agreement in simple terms

(posted) differences and connections between beanfactory and factorybean

Evolution of network IO model

How to set appium script startup parameters
![[training Day6] dream [priority queue] [greed]](/img/1b/309b53618b8a116862971799ce4e78.jpg)
[training Day6] dream [priority queue] [greed]

C form application treeview control use

clip:learning transferable visual models from natural language supervision

Pix2seq: Google brain proposes a unified interface for CV tasks!

Leetcode 48 rotating image (horizontal + main diagonal), leetcode 221 maximum square (dynamic programming DP indicates the answer value with ij as the lower right corner), leetcode 240 searching two-d

Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
随机推荐
vlan技术
Student achievement management system based on PHP
[advanced data processing technology] data filtering, advanced data filling, initial and advanced data transformation
The maximum number of expressions in ora-01795 list is 1000
clip:learning transferable visual models from natural language supervision
A new UI testing method: visual perception test
Processing of null value of Oracle notes
Do you want to enroll in a training class or study by yourself?
Merge sort
BGP - border gateway protocol
Oracle primary key auto increment setting
[sciter]: window communication
PHP page Jump mode
API data interface for historical data of A-share index
MySQL docker installation master-slave deployment
What does software testing need to learn?
Valdo2021 - vascular space segmentation in vascular disease detection challenge (3)
Do you want to verify and use the database in the interface test
Get the current time in go language, and the simple implementation of MD5, HMAC, SHA1 algorithms
Lunch break train & problem thinking: on multidimensional array statistics of the number of elements