yaml文件的介绍-K8S

yaml 文件是我们使用K8S管理应用程序常用的部署方式,它主要是通过一系列键值对组成,键和值使用冒号和空格分隔。以下是对yaml的介绍

在这里插入图片描述
首先我们可以使用命令生成一个简单的YAML模版文件

Kubectl run nginx-pod –image=nginx:latest –port=80 –dry-run=client -o yaml > nginx-pod.yaml 

其中nginx-pod 为pod 的名称 
–image=nginx:latest :最新的nginx 镜像
–dry-run=client :告诉kubectl 做测试使用,不告诉kubectl api
-o yaml :输出格式是yaml
> nginx-pod.yaml 将信息写入到文件中

以下是模版的详细介绍:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
spec:
  containers:
    - name: nginx-container
      image: nginx:latest 
      ports:
        - containerPort: 80

这个YAML文件等同于以下命令:
kubectl run nginx-pod --image=nginx:latest --port=80

使用YAML文件的额方法:

Kubectl apply -f nginx-pod.yaml 
Kubectl delete -f nginx-pod.yaml 
查看API对象及详细信息 
Kubeclt api-resources 
Kubectl explain pod.spec (资源字段)

生成YAML文件模板

  • 参考官方模板(https://v1-28.docs.kubernetes.io/zh-cn/docs/home/)
  • 通过命令生成模板,然后删除不用的属性

相关推荐

  1. k8s YAML文件详解

    2024-07-11 06:00:02       34 阅读
  2. 玩转k8syaml介绍

    2024-07-11 06:00:02       42 阅读
  3. K8S 哲学 - yaml文件

    2024-07-11 06:00:02       16 阅读
  4. k8s&&如何写yaml文件

    2024-07-11 06:00:02       16 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 06:00:02       7 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 06:00:02       7 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 06:00:02       5 阅读
  4. Python语言-面向对象

    2024-07-11 06:00:02       9 阅读

热门阅读

  1. ffmpeg 文档 - 未完

    2024-07-11 06:00:02       10 阅读
  2. Codeforces Round #956 (Div. 2) and ByteRace 2024

    2024-07-11 06:00:02       9 阅读
  3. 旅游 | 西岳华山

    2024-07-11 06:00:02       9 阅读
  4. 优化旅游服务热线系统以满足多样化需求

    2024-07-11 06:00:02       9 阅读
  5. vivado CONFIG_MODE、CONFIG_VOLTAGE

    2024-07-11 06:00:02       11 阅读
  6. 解锁SQL Server的迷宫:深入死锁的诊断与解决之道

    2024-07-11 06:00:02       10 阅读