Kubernetes - YAML file

Kubernetes support YAML and JSON formats to create resource objects

JSON格式用于接口之间消息的传递
YAML格式用于配置和管理
YAML是一种简洁的非标记性语言

Syntax

缩进标识层级关系
不支持制表符(tab)缩进,使用空格缩进
通常开头缩进两个空格
字符后缩进一个空格,如冒号,逗号等
“—”表示YAML格式,一个文件的开始
“#”表示注释
  • View application name
kubectl api-versions
  • demo Demonstration
mkdir demo

#编辑nginx-deployment.yaml文件
vim /demo/nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.4
        ports:
        - containerPort: 80

#创建nginx-deployment.yaml文件
kubectl create -f nginx-deployment.yaml

#查看pod节点
kubectl get pods

#编辑nginx-service.yaml文件
vim nginx-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: my-nginx-service
  labels:
    app: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: nginx

#创建nginx-service.yaml文件
kubectl create -f nginx-service.yaml

#查看服务
kubectl get svc

- Automatic test command correctness, does not perform creation

kubectl run nginx-deployment --image=nginx --port=80 --replicas=2 --dry-run
  • View yaml generation format
kubectl run nginx-deployment --image=nginx --port=80 --replicas=2 --dry-run -o yaml

- View generates json format

kubectl run nginx-deployment --image=nginx --port=80 --replicas=3 --dry-run -o json
  • Existing resources to generate export template
kubectl get deploy/nginx --export -o yaml
  • Saved to a file
kubectl get deploy/nginx --export -o yaml > my-deploy.yaml
  • See the field help
kubectl explain pods.spec.containers

thanks for reading!

Guess you like

Origin blog.51cto.com/14449521/2471929