In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what is the use of yaml files in Kubernetes, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
YAML Foundation
YAML (Yet Another Markup Language) is not a markup language. It has a wide range of applications, and here we will focus on some of the contents in Kubernetes. Using the definition of YAML for k8s will give you some benefits, including:
Convenience: you will no longer need to add a large number of parameters to the command line to execute commands
Maintainability: YAML files can be controlled by source and can track each operation
Flexibility: with YAML you will be able to create structures that are more complex than the command line. YAML is a superset of JSON, meaning that any valid JSON file is also a YAML file. With regard to the use of YAML in Kubernetes, you only need to know two types:
Maps
Lists
YAML Maps
Let's first take a look at the YAML Maps type. Maps can combine keys and values to make it easier to configure information. Like this, you may have this configuration information:
-
ApiVersion: v1
Kind: Service
The first line is a delimiter and is optional. If only one service is defined in a single file, the delimiter on the first line can be ignored. In the above example, you can see that there are two values: v1 and Service, whose keys are apiVersion and kind
YAML Lists
Next, let's introduce YAML Lists. In fact, it is a sequence of objects, such as:
Args
-sleep
-"1000"
-message
We can see that there can be any number of items in the list, the definition of the item begins with a dash (-), and there is indentation with the parent element. One thing to note, though: never use the tab key for indentation in YAML files.
Application in practice
Basically, no matter what kind of structure we want, we can combine these two structures. Next, I'll take the yaml file I used in the project as an example to explain (# later for comments):
ApiVersion: v1
Kind: the ReplicationController # type is a RC
Metadata:
Name: nginx-controller
Spec:
Replicas: 2 # I want 2 RC
Selector:
Name: mynginx
Template:
Metadata:
Labels:
Name: mynginx
Spec:
Containers:
-name: mynginx
Image: reg . Zll . Com/web/nginx:1 . twelve. The 2 # frontend needs to be deployed on the nginx. Here is the image of the corresponding nginx.
VolumeMounts:
-name: httpd-storage
MountPath: / etc/nginx/nginx . The configuration file address of nginx in the conf # image, using the path:/home/nginx below. Conf to replace this path.
-name: httpd-storag
MountPath: / usr/local/dist
Ports:
-containerPort: 80
Volumes:
-name: httpd-storage
HostPath:
Path: / home/nginx . The configuration file of conf # custom nginx is mounted to this path on the server to replace the configuration of nginx in the image
-name: httpd-storag
HostPath:
Path: / usr/local/dist # the file packaged at the front end, the path to be placed, to replace the mountPath:/usr/local/dist uploaded
-
ApiVersion: v1
Kind: the Service # type is a service
Metadata:
Name: nginx-service-nodeport
Spec:
Ports:
-port: 8000
TargetPort: 80
NodePort: 30080 # exposes accessible IP.
Protocol: TCP
Type: NodePort
Selector:
Name: mynginx above is all the content of the article "what's the use of yaml files in Kubernetes?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.
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.