Two Resource Creation Methods

Source: Internet
Author: User

Command vs configuration file

Kubernetes supports two resource creation methods:

1. Use the kubectl command to directly create
 
Kubectl run nginx-deployment -- image = nginx:1.7.9-- Replicas =2

 

Specify the resource attributes through parameters in the command line.

2. Through the configuration file and Kubectl apply Create

To do the same job, run the following command:

[[Email protected] k8s] # kubectl apply-F nginx. yaml
Deployment. Extensions/nginx-deployment configured

 

3. nginx. yml Content Description
Apiversion: extensions/V1beta1 # API version kind: Deployment # Resource Type metadata: # resource metadata name: nginx-Deployment # Resource Name SPEC: # Resource Description replicas:2# Two copies. The default value is 1 template: # pod template metadata: # pod metadata labels: # tag app: web_server # tag selector SPEC: containers:-Name: nginx image: nginx:1.79

 

Resource attributes are written in the configuration file in the format of yaml.

This configuration file has extremely strict format requirements. It cannot be indented incorrectly and cannot contain less space. The highlighted prompt in the vim editor will help us write the configuration file. If the syntax is incorrect, it will be detected.

 

4. Compare the two methods

Command-based methods:

    1. Simple, intuitive, and easy to use.

    2. Suitable for temporary tests or experiments.

Configuration file-based methods:

    1. The configuration file describesWhatThat is, the final state of the application.

    2. The configuration file provides a template for creating resources and can be deployed repeatedly.

    3. You can manage the deployment as you manage the code.

    4. It is suitable for formal, cross-environment, and large-scale deployment.

    5. This method requires familiarity with the syntax of the configuration file, which is difficult.

 

Kubectl applyIt is convenient to create kubernetes resources and update resources. However, kubernets also provides several similar commands, suchKubectl create,Kubectl replace,Kubectl EditAndKubectl patch.

To avoid unnecessary troubles, we will try to use onlyKubectl apply,
This command has been able to cope with more than 90% of scenarios, get twice the result with half the effort.

 

5. Deletion of resources

The resources created in the configuration file can also be deleted in the previous way.

[[Email protected] k8s] # kubectl apply-F nginx. yaml deployment. Extensions/Nginx-deployment created

Delete Configuration

 
[[Email protected] k8s] # kubectl Delete-F nginx. yaml deployment. Extensions"Nginx-deployment"Deleted

 

Two Resource Creation Methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.