This is the 8th day of my participation in Gwen Challenge
Use the configuration list
Apiserver only receives the resource definition in JSON format. Yaml format defines the configuration list. Apiserver automatically converts the list to JSON format and executes it.
5.1 Configurable Objects
- An object configured with the list of available resources
Workload: Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, CronJob Service discovery and balancing: Service, Ingress configuration and storage: Volume, CSI ConfigMap, and Secret DownwardAPI Cluster resources Namespace, None, Role, ClusterRole, RoleBinding, and ClusterRoleBinding metadata resources HPA, PodTemplate, LimitRangeCopy the code
5.2 Configuration List Composition
- Most resources are created using a configuration list
apiVersion
# specify which API group (version) this object belongs to as "group/version"
kind:
What type of resource does the tag create
metadata:
Inside metadata are nested fields
Defines resource object names, namespaces (k8S level not system), tags, annotations, etc
spec:
The specification defines what properties a resource should have, relying on the controller to ensure that those properties are met
# It is a user-defined expected resource state
status:
K8s is to ensure that the current state is infinitely close to the target state to meet user expectations
It is read-only and represents the current state of the resource
Copy the code
- Get the full API version
kubectl api-versions
Copy the code
- Get all API resource objects
You can see some abbreviations from the content, which is convenient for us to write abbreviations after daily commands
kubectl api-resources
kubectl get po # to check the pod
kubectl get deploy # see deployment
kubectl get svc # to check the service
kubectl get cm # see configmap.Copy the code
5.3 Obtaining List Help
- To view the configuration list format of a k8S built-in object, which fields should be included, use. To display field formatting help information
kubectl explain pods
kubectl explain pods.metadata
Copy the code
5.4 Basic format of listing
- Define a resource list
apiVersion: v1
kind: Pod
metadata:
name: pod-deme
namespace: default
labels:
app: myapp
tier: frontend
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
- name: busybox
image: busybox:latest
command:
- "/bin/sh"
- "-c"
- "sleep 10"
Copy the code
5.5 Quick List Retrieval
- Use the -o argument to specify the output format of the object data, and use –dry-run to test the execution of a command. The combination of the two can be created by command and generate a YAML configuration file
kubectl create secret docker-registry regsecret --docker-server=registry-vpc.cn-hangzhou.aliyuncs.com --docker-username=admin --docker-password=123456 [email protected] -o yaml --dry-run
Copy the code
5.6 create create
- Create a resource in the resource list. In this way, the created resource is a bare POD. There is no controller to manage the resource
kubectl create -f pod-demo.yaml
Copy the code
5.7 delete delete
- Delete the POD defined in the resource manifest
kubectl delete -f pod-demo.yaml
Copy the code
5.8 Apply creates or updates
Apply can be executed multiple times and updated if the files are found to be different
kubectl apply -f pod-demo.yaml
Copy the code
5.9 Patch Updating resources
Different from Apply, patch does not need to modify the resource list file when it is renamed. It can directly update the resource object fields and supports JSON and YAML formats.
Update Node nodes using patch.
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
Copy the code
other
Send your notes to: github.com/redhatxl/aw… Welcome one button three links