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

Two ways for kubernetes to create Resources

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

Share

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

Overview of Kubernetes

Kubernetes is an open source container orchestration engine for Google, which supports automated deployment, large-scale scalability, and application containerization management. When deploying an application in a production environment, multiple instances of the application are usually deployed to load balance application requests.

In Kubernetes, we can create multiple containers, each running an application instance, and then manage, discover and access this group of application instances through the built-in load balancing policy, and these details do not need to be manually configured and processed by the operation and maintenance staff.

The resources of K8S include Pod, Service, Volume, Namespace, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job and so on.

Profile-based approach: the profile describes the What, the state that the application will eventually reach. The configuration file provides a template for creating resources that can be deployed repeatedly. You can manage your deployment as if you were managing code. Suitable for formal, cross-environmental, large-scale deployment. This approach requires familiarity with the syntax of the configuration file, which is difficult. First, create the IP address of the resource host by command line. Master192.168.1.21node01192.168.1.22node02192.168.1.23 only accepts the configuration list in json format (yml, yaml) [root@master ~] # cd / etc/kubernetes/manifests///k8s yml, yaml file 1.node01 and node02 download nginx image docker pull nginx// download nginx image 2.master to create Pod controller (test-web) Deployment [root@master ~] # kubectl run test-web-- image=nginx-- replicas=5// create Pod controller, deployment3. Check the controller situation (1) [root@master ~] # kubectl get deployments.// View the controller situation

[root@master ~] # kubectl get pod-- all-namespaces-o wide// displays node information of pod

(2) [root@master ~] # kubectl get namespaces / / View k8s namespace

[root@master] # kubectl describe deployments. Test-web// view resource details

To view a resource object, no namespace is specified and the default is in the default namespace. You can add the-n option to view the resources of the specified namespace.

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

3. Delete the test-web controller [root@master ~] # kubectl delete deployments. Test-web 4.master creates a Pod controller (web), deployment [root@master ~] # kubectl run web-- image=nginx-- replicas=5 to check the pod information [root@master ~] # kubectl get pod-o wide// to view the node information of pod

[root@master] # kubectl describe deployments. Web / / View resource details

Note: running the created deployment resource object directly is a frequently used controller resource type. In addition to deployment, there are rc, rs, and other pod controllers. Deployment is an advanced pod controller.

Native test access to nginx [root@master ~] # curl 10.244.1.7

5. Create service resource type [root@master ~] # kubectl expose deployment web--name=web-xgp-- port=80-- type=NodePort// create service resource type, here we set the mapping port

If you want the public network to be able to access the service, you can expose deployment resources and get service resources, but the type of svc resources must be NodePort.

Mapped port range: 30000-32767

View service information [root@master ~] # kubectl get svc

Browser test access to http://192.168.1.21:30493/

Second, the expansion and reduction of service capacity 1. View the controller information [root@master ~] # kubectl get deployments. -o wide

two。 Expand [root@master ~] # kubectl scale deployment web-- replicas=8 take a look at [root@master ~] # kubectl get deployments. -o wide

3. Scale down [root@master ~] # kubectl scale deployment web-- replicas=4 check [root@master ~] # kubectl get deployments. -o wide

3. Backup the yaml file of web [root@master ~] # kubectl get deployments by modifying web's yaml file to expand and reduce the capacity. -o yaml > web.yaml use edit to modify web's yaml file [root@master ~] # kubectl edit deployments. Web

Check out [root@master ~] # kubectl get deployments. -o wide

III. Service upgrade and rollback node01 and node02 download version 1.15 of nginx [root@master ~] # docker pull nginx:1.151.master Settings Service upgrade [root@master ~] # kubectl set image deployment web web=nginx:1.15 check it out

2.master Settings Service rollback (1) modify configuration file rollback use edit to modify web's yaml file [root@master ~] # kubectl edit deployments. Web

Check out [root@master ~] # kubectl get deployments. -o wide

(2) Command rollback [root@master ~] # kubectl rollout undo deployment web

Note: can only be rolled back to the state of the previous operation

Fourth, the small experimental environment host IP address service master192.168.1.21registry+Deploymentnode01192.168.1.22node02192.168.1.231.master based on httpd to make its own image, need 3 versions, v1memv2memv3. And the corresponding version image The contents of the home directory visited are different (1) master downloads the httpd image [root@master ~] # docker pull httpd (2) write a document [root @ master xgp] # vim DockerfileFROM httpdCOPY index.html / usr/local/apache2/htdocs/index.html (3) create a test web page v1 [root@master xgp] # echo "xgp | test-web | httpd:v1" > index.html (4) create an image web1 [root@master xgp] # docker build-t web1 based on Dockerfile. (5) ) create a test web page v2 [root@master xgp] # echo "xgp | test-web | httpd:v1" > index.html (6) create an image web2 [root@master xgp] # docker build-t web2 based on Dockerfile. (7) create a test page v3 [root@master xgp] # echo "xgp | test-web | httpd:v3" > index.html (8) create an image web3 [root@master xgp] # docker build-t web3 .2.master deployment private warehouse based on Dockerfile Library (1) master download registry image [root@master ~] # docker pull registry (2) launch registry[ root @ master xgp] # docker run-itd-- name registry-p 5000Ranger 5000-- restart=always registry:latest (3) modify docker configuration file Join the private warehouse (three sets) [root@master xgp] # vim / usr/lib/systemd/system/docker.serviceExecStart=/usr/bin/dockerd-- insecure-registry 192.168.1.21 VOL5000

(4) restart docker (three) [root@master xgp] # systemctl daemon-reload [root@master xgp] # systemctl restart docker3. Upload the three web images created before upload to the private repository (1) modify the image tag [root@master xgp] # docker tag web1:latest 192.168.1.21:5000/web1:latest [root@master xgp] # docker tag web2:latest 192.168.1.21:5000/web2:latest [root@master xgp] # docker tag web3:latest 192.168.1.21:5000/web3:latest (2) upload three web images to the private repository [root@] Master xgp] # docker push 192.168.1.21:5000/web1:latest [root@master xgp] # docker push 192.168.1.21:5000/web2:latest [root@master xgp] # docker push 192.168.1.21:5000/web3:latest 4. Deploy a Deployment resource object, which requires the image to use the above private image v1 version. 6 copies of Pod. [root@master xgp] # kubectl run www1-- image=192.168.1.21:5000/web1:latest-- replicas=6 check [root@master xgp] # kubectl get pod

5. Expose the above Deployment to a service resource object, so that the public network can access the service. [root@master xgp] # kubectl expose deployment www1-- name=web-xgp-- port=80-- type=NodePort check [root@master xgp] # kubectl get svc

Visit the browser.

6. The above Deployment is expanded and reduced to 8 replicas Pod, and then reduced to 4 replicas Pod. (1) expand [root@master xgp] # kubectl scale deployment www1-- replicas=8 to see [root@master xgp] # kubectl get deployments. -o wide

(2) scale down and modify k8s configuration file to back up the yaml file [root@master ~] # kubectl get deployments of web. -o yaml > www1.yaml use edit to modify web's yaml file [root@master ~] # kubectl edit deployments. Www1

Check out [root@master xgp] # kubectl get deployments. -o wide

7. Upgrade and roll back the above Deployment, and upgrade v1 version to v2 version. (1) upgrade version to web2 [root@master ~] # kubectl set image deployment www1 www1=192.168.1.21:5000/web2 Native Test access [root@master ~] # curl 127.0.0.1:30996xgp | test-web | httpd:v2

Browser test access

(2) Roll back the version to web1 modify configuration file rollback the yaml file [root@master ~] # kubectl edit deployments of web modified by edit. Www1

Check out [root@master ~] # kubectl get deployments. -o wide

Make a visit.

Command rollback [root@master ~] # kubectl rollout undo deployment www1

Note: can only be rolled back to the state of the previous operation

Make a visit.

_ _ over _

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