5、k8s-资源管理-yaml语言--使用yaml语言创建nginx服务

YAML语言是一个类似XML、JSON的标记性语言、他强调以数据为中心、而不是以标识语言为重点、因而YANL本身定义比较简单:对比如下

XML语言:
<html>
    <age>15< /age>
    <address>hainan< /address>
</html>

YAML语言:
heima:
    age:15
    address:hainan

yaml语言没有过多的标记性嵌套字符

 

纯量:

 

对象:

 

数组:

 

 

例子:创建nginx服务

apiVersion: v1
kind: Namespace
metadata:
  name: bmc
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: bmc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: bmc
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

 

posted @ 2024-06-18 14:47  little小新  阅读(10)  评论(0编辑  收藏  举报