In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1. Resource restrictions:
Resource requests and restrictions for pod and container:
Spec.containers [] .resources.recips.cpu # cpu limit
Spec.containers [] .resources.invents.memory # memory limit
Spec.containers [] .resources.requests.cpu # basic cpu resources allocated when created
Spec.containers [] .resources.requests.memory # basic memory resources allocated when created
Example (operating on master1): [root@master1 demo] # vim pod2.yamlapiVersion: v1kind: Podmetadata: name: frontend # name of Pod resource spec: containers:-name: db # Container 1 name image: mysql env:-name: MYSQL_ROOT_PASSWORD value: "password" resources: requests: memory: "64Mi" cpu: "250m" Limits: memory: "128Mi" cpu: "500m"-name: wp # Container 2 name image: wordpress resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m" # after insertion is completed Press Esc to exit the insertion mode, and enter: wq save exit `create resource `[root@master1 demo] # kubectl apply-f pod2.yamlpod/frontend created` to view resource details` [root@master1 demo] # kubectl describe pod frontendName: defaultPriority: 0PriorityClassName: Node: 192.168.18.148Accord 192.168.18.148 # the node to which the resource is assigned is node1. Multiple lines of Events are omitted here: Type Reason Age From Message-Normal Scheduled 89s default-scheduler Successfully assigned default/frontend to 192.168.18.148 Normal Pulling 88s kubelet, 192.168.18.148 pulling image "mysql" Normal Pulled 23s kubelet 192.168.18.148 Successfully pulled image "mysql" Normal Created 23s kubelet, 192.168.18.148 Created container Normal Started 22s kubelet, 192.168.18.148 Started container Normal Pulling 22s kubelet 192.168.18.148 pulling image "wordpress" # is in the mirror pull wordpress state [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEfrontend 2 + 2 Running 0 4m26s# then the two containers will be in the Running running status` check the Pod resource usage on the corresponding nodes` [root@] Master1 demo] # kubectl describe nodes 192.168.18.148Name: 192.168.18.148. Omit multiple lines Allocated resources: (Total limits may be over 100percent, i.e., overcommitted.) Resource Requests Limits-cpu 550m (55%) 1100m (110%) # Core resources memory 228Mi (13%) 556Mi (32%) # Upper limit resources `View namespace `[root@master1 demo] # kubectl get nsNAME STATUS AGEdefault Active 13dkube-public Active 13dkube-system As long as Active 13d# is not specified by-n What appears is the default three restart policies:
1:Always: always restart the container when it is terminated. Default policy
2:Onfailure: restart the container when the container exits abnormally (the exit code is non-0)
3:Never: never restart resources when the container terminates and exits
Note: restart pod resources is not supported in K8s, only delete and rebuild
Example (operating on master1): `default restart policy is Always` [root@master1 demo] # kubectl edit deploy# input / restartPolicy lookup restartPolicy: Always # defaults to Always [root@master1 demo] # vim pod3.yamlapiVersion: Podmetadata: name: foospec: containers:-name: busybox image: busybox args: / bin/sh # in shell environment when no restart policy is set-- C # command command-sleep 30 Exit 3 # container hibernates for 30 seconds after startup, and the return status code for exception exit is a non-zero value. # after the insertion is completed, press Esc to exit the insertion mode Enter: wq save exit [root@master1 demo] # kubectl apply-f pod3.yamlpod/foo created [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEfoo 0 ContainerCreating 1 ContainerCreating 0 18s# with RESTARTS restart value At this time, it is 0 [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEfoo 0swap 1 Error 0 62s#. There is an Error error at this time because of the abnormal exit we just set. When you check it later, the RESTARTS restart value will become 1. `This is the `[root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEfoo 1 Running 1 Running 1 3m13s` that is executed according to the restart policy. Delete the previously created resource first. Because it will occupy `[root@master1 demo] # kubectl delete-f pod3.yamlpod "foo" deleted [root@master1 demo] # kubectl delete-f pod2.yamlpod "frontend" deleted` to add restart policy Never` [root@master1 demo] # vim pod3.yamlapiVersion: v1kind: Podmetadata: name: foospec: containers:-name: busybox image: busybox args:-/ bin/sh-- c-sleep 10 # modify the dormancy time to 10s RestartPolicy: Never # add restart policy # after modification Press Esc to exit insert mode Enter: wq save exit [root@master1 demo] # kubectl apply-f pod3.yamlpod/foo created [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEfoo 1 Running 0 14s [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEfoo 0apace 1 Completed 0 65s# the resource is created at this time It will sleep automatically when it is not needed, because a restart policy is added between them, so it will not be restarted. 3. Health check: also known as Probe Note: rules can be defined at the same time
If livenessProbe fails to check, it will kill the container and operate according to Pod's restartPolicy.
If ReadinessProbe fails to check, kubernetes will remove Pod from the service endpoints backend node.
Probe supports three inspection methods:
HttpGet sends http request. The status code in the range of 200-400 is successful.
Exec executes the Shell command and returns a status code of 0 as successful.
TcpSocket initiated TCP Socket to establish successfully
Example exec mode (operating on master1): [root@master1 demo] # vim pod4.yamlapiVersion: v1kind: Podmetadata: labels: test: liveness name: liveness-execspec: containers:-name: liveness image: busybox args:-/ bin/sh-- c-touch / tmp/healthy; sleep 30 Rm-rf / tmp/healthy # create an empty file and hibernate for 30s Delete the empty file livenessProbe: exec: # probe Health command: # command Command-cat # execute View-/ tmp/healthy # empty file created by initialDelaySeconds: 5 # the container is created 5 seconds after the completion of the health check periodSeconds: 5 # check frequency is 5 seconds `Hugh Check the status before sleep and the return value is 0 Check after 30 seconds of dormancy. Because without this file, a non-0 value will be returned ``Refresh Resource `[root@master1 demo] # kubectl apply-f pod4.yamlpod/liveness-exec created [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEliveness-exec 1According to 1 Running 0 24s [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEliveness-exec 0/1 Completed 0 53s [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEliveness-exec 1/1 Running 1 67s [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEliveness-exec 0 CrashLoopBackOff 1 109s [root@master1 demo] # kubectl get podsNAME READY STATUS RESTARTS AGEliveness-exec 1 Running 2 2m5s# the state is constantly changing It means that it is constantly checking, and then constantly implementing the restart policy, in which the RESTARTS restart value will increase.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.