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

What are the two ways for k8s to create resources?

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

In this issue, the editor will bring you what are the two ways to create resources for K8s. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Command vs configuration file

Kubernetes supports two ways to create resources:

1. Create it directly with the kubectl command, such as:

Kubectl run nginx-deployment-image=nginx:1.7.9-replicas=2

Specify the properties of the resource through parameters on the command line.

two。 To do the same with configuration files and kubectl apply creation, execute the command:

Kubectl apply-f nginx.yml

The content of nginx.yml is:

The properties of the resource are written in the configuration file, and the file format is YAML.

The two ways are compared below.

Command-based approach:

Simple, intuitive and fast, quick to use.

Suitable for temporary tests or experiments.

Profile-based approach:

The configuration file describes the What, that is, the state that the application will eventually achieve.

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.

Later, we will all use the way of configuration files, which we need to be familiar with and master as soon as possible.

Kubectl apply can not only create Kubernetes resources, but also update resources, which is very convenient. However, Kubernets provides several similar commands, such as kubectl create, kubectl replace, kubectl edit, and kubectl patch.

To avoid causing unnecessary trouble, we will try to use only kubectl apply.

This command has been able to deal with more than 90% of the scenarios and get twice the result with half the effort.

These are the two ways for the editor to create resources for the shared K8s. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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