In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
K8s core resource object:
Pod: the atomic unit of operation and scheduling, that is, the smallest resource unit in K8s. The same pod can run multiple container at the same time, and multiple container can be shared: (UTS (hostname and domain name), IPC (message queue and shared memory), NET (network stack, port, etc.), namespace (namespace), but USR (user and group), MNT (mount point), PID (numbering) are isolated from each other.
There are two types of pod in pod: one is the pod controlled by the controller, and the other is the autonomous pod (which is not managed by the controller and manages itself)
Deployment: the most common pod controller, which supports the expansion and scaling of applications. Scroll the update operation. (disadvantage: unable to roll back to the specified version)
Service: provides a fixed and unified access interface for lifecycle pod objects for service discovery and service access.
The following resource objects will be applied in subsequent blogs, and the following is just to learn about RC (Replcation Controller): the earliest generation of pod controllers, which will be deleted in future versions.
RS (Replication Set): a new generation of pod controller, used to replace RC, has basically the same function as RC, except that it supports different tag selectors. RC only supports equivalent selectors, and RS also supports set-based selectors.
DaemonSet: used to ensure that each node is running a copy of a pod. (only one copy is run per node, and the replicas field is not supported)
Job: used to manage applications that can be terminated after running, such as batch processing job tasks (can be understood as pod in turn, and delete pod as soon as the task is completed)
PV (PersistentVolume): persistent volume, unified data persistence directory, easy to manage
* PVC (PersistentVolumeClaim): an application for persistent space using pv, declaration.
Stroage Class: (storage class) fundamental function: automatically create a pv based on the values defined by pv.
StatefulSet: also known as PetSet, is also a kind of pod controller.
Features: the name of pod remains the same, and each copy starts and stops in order. For data persistence (the data is different for each pod), the pv,pvc is created automatically.
Secret and ConfigMap: used to store lightweight and sensitive information. For example, the user name and password of the database or the authentication key.
* Ingress-nginx: used to solve the load situation of the cluster and provide a unified intersection for the cluster. Security, port container management.
NameSpace (Namespace)
NameSpace (Namespace) is another important concept in the kubernetes system. By "assigning" objects within the system to different namespace to form logically grouped different projects, groups or user groups, different groups can be managed separately while sharing the resources of the entire cluster.
After the kubernetes cluster starts, it creates a NameSpace named "default". If NameSpace is not specifically specified, the user-created pod,RC and Service are created by the system into the NameSpace of "default".
NameSpace in kubernetes is mainly used for spatial and name isolation, which is completely different from the concept of NameSpace in docker.
[root@master ~] # kubectl get ns / / View namespace NAME STATUS AGEdefault Active 27d / / default namespace is defaultkube-node-lease Active 27dkube-public Active 27dkube-system Active 27d
Create a namespace
# # there are two creation methods: command line and writing yaml file
/ / method 1: create command line
[root@master ~] # kubectl create ns k8s1namespace/k8s1 created
/ / method 2: write yaml files
[root@master ~] # vim k8s2-ns.yamlapiVersion: v1kind: Namespacemetadata: name: k8s2 [root@master ~] # kubectl apply-f k8s2-ns.yaml namespace/k8s2 created
Application of Namespace
1, specify a pod (httpd) to run in the specified namespace:
[root@master ~] # vim test-pod1.yamlapiVersion: extensions/v1beta1kind: Deploymentmetadata: name: test-pod1 namespace: k8s2 / / specify the namespace spec: revisionHistoryLimit: 5 replicas: 2 template: metadata: labels: name: httpd-web spec: containers:-name: httpd image: httpd ports:-containerPort: 80 [root@master ~ ] # kubectl apply-f test-pod1.yaml deployment.extensions/test-pod1 created// View the pod under this namespace: [root@master ~] # kubectl get pod-n k8s2 #-n: specify the namespace NAME READY STATUS RESTARTS AGEtest-pod1-55b448f88c-mhmqc 1 4m6stest-pod1 1 Running 0 4m6stest-pod1-55b448f88c-xqsr7 1 Running 0 4m6s
PS: when viewing resource objects under any namespace, you need to specify the corresponding namespace, otherwise the pod under the default namespace is viewed by default.
Rollback of the specified version of the namespace application
In the resource creation blog in the previous chapter, we used version upgrade and rollback operations, but only between the two versions, which is a great disadvantage, and the next operation is to specify a version to roll back.
/ / create a deployment resource object under the specified namespace. The image uses the image in the private repository for update and rollback operations, and verifies the web page.
1) build a registry private repository and upload a custom image. For more information, please refer to the blog article to deploy the private repository.
2) create a resource object:
[root@master ~] # vim namespace-pod1.yaml
ApiVersion: v1kind: Namespace # create namespace metadata: name: test-namespace---apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginx-deploy1 namespace: test-namespacespec: template: metadata: labels: name: nginx-web # create deployment spec: containers:-name: nginx image: 172.16.1.30:5000/nginx:v1 ports: -containerPort: 80---apiVersion: v1kind: Servicemetadata: name: nginx-svc namespace: test-namespacespec: type: NodePort # create the service association deployment selector: name: nginx-web ports:-name: nginx port: 80 targetPort: 80 nodePort: 30001pm / run the pod [root@master ~] # kubectl apply-f namespace-pod1.yaml-- record namespace/test-namespace configureddeployment.extensions/nginx-deploy1 configuredservice/nginx-svc configured parameter:-- record: record the version information. / / View deployment version information: [root@master ~] # kubectl get deployments. -o wide-n test-namespace
/ / visit the web interface:
3) update the image version to v2 version:
[root@master ~] # cp namespace-pod1.yaml namespace-pod2.yaml [root@master ~] # vim namespace-pod2.yaml
[root@master ~] # kubectl apply-f namespace-pod2.yaml-- record # record version information namespace/test-namespace configureddeployment.extensions/nginx-deploy1 configuredservice/nginx-svc configured// View the current image version: [root@master ~] # kubectl get deployments. -o wide-n test-namespace
/ / Image updated successfully. Visit the web page:
4) Roll back to the specified version 1:
/ / check the historical version information before rollback: [root@master ~] # kubectl rollout history deployment-n test-namespace
Because I only updated once, so there are only two versions, of course, there must be a lot of versions in the production environment, so we have to be able to specify the corresponding version.
/ / rollback:
[root@master ~] # kubectl rollout undo deployment-n test-namespace nginx-deploy1-- to-revision=1deployment.extensions/nginx-deploy1 rolled back--to-revision parameter to specify the version, just select the corresponding version number.
/ / check the version of deployment to see whether the rollback is successful:
The version rollback is successful. The test accesses the web interface:
You can see that the rollback was successful and the content of the web page was rolled back.
/ / check the historical version information again:
You can see that after the rollback operation, the previous version 1 has become the latest version 3, and the versions are arranged in order.
-this is the end of this article. Thank you for reading-
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.