Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Pod resource object

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Deployment,Service,Pod is the three core resource objects of K8s. Deployment: the most common controller for stateless applications, which supports expansion, rolling update and other operations of the application. Service: provides a fixed access interface for flexible and lifecycle Pod objects for service discovery and service access. Pod: the smallest unit for running containers and scheduling. The same Pod can run multiple containers at the same time, and these containers share NET,UTS,IPC. In addition, there is USER,PID,MOUNT.ReplicationController: to ensure that each Pod copy can meet the target number at any time, simply put, it is used to ensure that each container or container group is always running and accessible: the old generation of stateless Pod application controllers. ReplicaSet: a new generation of stateless Pod application controller, which differs from RC in that it supports tag selectors. RC only supports equivalent selectors, while RS also supports set-based selectors. StatefulSet: used to manage stateful persistence applications, such as database service programs, it differs from Deployment in that it creates a separate persistence identifier for each Pod and ensures sequence between each Pod. DaemonSet: used to ensure that each node runs a copy of a Pod, the new node will also be added with this Pod, and such Pod will be recycled when the node is removed. Job: used to manage applications that can be terminated after running, such as batch processing job tasks. Volume:PV PVCConfigMap: stores common configuration variables, similar to configuration files, so that users can unify the environment variables used for different modules in the distributed system into one object; it differs from configuration files in that it exists in the "environment" of the cluster and supports all common operations in the K8S cluster. Secret: a K8s resource used to hold small pieces of sensitive data, such as passwords, token, or keys. Of course, this kind of data can also be stored in Pod or images, but it is placed in Secret to make it easier to control how the data is used and to reduce the risk of exposure. Role: indicates that it is a set of regular permissions, which can only be accumulated. Role can be defined in a namespace and can only be used to grant access to resources in a single namespace. For example, we create a new pair in the default namespace. ClusterRole:RoleBinding:ClusterRoleBinding:Service account:Helm:Namespace: namespace

Default namespace: Default

/ / View namespaces

[root@master ~] # kubectl get ns

/ / View namespace details

[root@master ~] # kubectl describe ns default

/ / create a namespace

[root@master ~] # kubectl create ns bdqn

[root@master ~] # kubectl explain ns

[root@master ~] # vim 111-test.yamlapiVersion: v1kind: Namespacemetadata: name: test [root@master ~] # kubectl apply-f 111-test.yaml [root@master ~] # kubectl get ns

There are two ways to delete a resource:

[root@master ~] # kubectl delete ns test [root@master ~] # kubectl delete-f 111-test.yaml

Ps: namespace resource objects are only used for isolation of resource objects, and can not be separated from the communication between Pod of never different namespaces, which is the function of network policy resources.

Resources with a specified namespace can be viewed using the-- namespace or-n option

[root@master] # kubectl get pod-- namespace=bdqn No resources found.

Abbreviation:

[root@master] # kubectl get pod-n bdqn No resources found.

View the Pod running in this cluster

[root@master ~] # kubectl get pod-n kube-system Pod [root@master ~] # vim pod.yamlkind: PodapiVersion: v1metadata: name: test-podspec: containers:-name: test-app image: httpd [root@master ~] # kubectl apply-f pod.yaml pod/test-pod created

[root@master ~] # kubectl get pod

[root@master ~] # vim pod.yamlkind: PodapiVersion: v1metadata: name: test-pod namespace: bdqn / / add a line spec: containers:-name: test-app image: httpd

Regenerate:

[root@master] # kubectl apply-f pod.yaml pod/test-pod created

View bdqn namespaces

[root@master] # kubectl get pod-n bdqn NAME READY STATUS RESTARTS AGEtest-pod 1 Running 0 80s

Image acquisition policy in Pod:

Always: always get the image from the specified repository when the image is labeled "latest" or when the image does not exist. IfNotPresent: download from the target repository only if the local image does not exist. Never: do not download images from the repository, that is, only use local images.

PS: for tags "latest" or non-existent, the default policy download and policy is "Always", while for other tag images, the default policy is "IfNotPresent".

[root@master ~] # vim pod.yaml kind: PodapiVersion: v1metadata: name: test-pod namespace: bdqnspec: containers:-name: test-app image: httpd imagePullPolicy: IfNotPresent ports:-protocol: TCP containerPort: 80 [root@master ~] # kubectl delete pod-n bdqn test-pod pod "test-pod" deleted [root@master ~] # kubectl apply-f pod.yaml pod/test-pod created [root@master ~] # kubectl apply-f pod.yaml pod/test- Pod created [root@master ~] # kubectl get pod-n bdqnNAME READY STATUS RESTARTS AGEtest-pod 1Accord 1 Running 026s final effect: [root@master ~] # vim pod.yaml kind: PodapiVersion: v1metadata: name: test-pod namespace: bdqn labels: app: test-webspec: containers:-name: test-app image: httpd imagePullPolicy: IfNotPresent ports:-protocol: TCP containerPort: 90 [root@master ~] # vim svc.yamlapiVersion: v1kind: Servicemetadata: name: test-svc namespace: bdqnspec: selector: app: test-web ports:-port: 80 targetPort: 90

[root@master] # kubectl describe svc-n bdqn test-svc

Container restart policy Always: the DSLR Pod object is restarted when it terminates. This is the default setting. OnFailure: restart the Pod object only if there is an error. Never: never restarts. Pod default health check [root@master ~] # vim healcheck.yamlapiVersion: v1kind: Podmetadata: labels: test: healcheck name: healcheckspec: restartPolicy: OnFailure containers:-name: healthcheck image: busybox args:-/ bin/sh-- c-sleep 20; exit 1

[root@master] # kubectl apply-f healcheck.yaml

[root@master] # kubectl get pod-w

[root@master] # kubectl get pod-n kube-system

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report