kubernetes创建yaml模版

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/meifannao789456/article/details/89139703

Pod模版yaml文件

apiVersion: v1
# 资源对象的类型
kind: Pod
metadata:
  name: nginx-gt
  namespace: default
  label:
    app: nginx-gt
spec:
  # 为pod的hosts 文件中增加 dev-cer.getui.com 记录
  hostAliases:
  - hostnames:
    - dev-cer.xiuxiuing.com
    ip: 192.168.10.53
  # 为 pod 引入裸机上的挂载目录
  volumes:
    - hostPath:
      path: /app/k8s/test
      name: logs
  # init 容器
  initContainers:
  - name: my-busybox
    image: busybox
    command: ["sh", "-c", "echo hello-world!"]
  # 应用容器
  containers:
  - name: my-nginx
    image: nginx:1.15
    # 为应用容器挂载引入的目录
    volumeMounts:
    - mountPath: /etc/nginx/logs
      name: logs
    # 设置容器运行开放的端口
    ports:
    - containerPort: 80
      name: http-service
    command: ["nginx", "-g", "daemon off;"]
    # pod 钩子
    lifecycle:
      postStart:
        exec:
          command: ["sh", "-c", "echo container start..."]
      preStop:
        exec:
          command: ["sh","-c","echo container quit..."]
    # pod 探针
    ## pod 准备就绪探针
    readinessProbe:
      exec:
        command:
        - cat
        - /etc/nginx/nginx.conf
      initialDelaySeconds: 10
      periodSeconds: 5
    ## pod 运行探针
    livenessProbe:
      exec:
        command:
        - cat
        - /etc/nginx/nginx.conf
      initialDelaySeconds: 10
      periodSeconds: 5
  # pod 能容忍的污点
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300

Service 模板yaml文件

{
	"kind": "Service",
	"apiVersion": "v1",
	"metadata": {
	  "name": "nginx-gt",
	  "namespace": "default"
	 },
	"spec": {
	  "ports": [
	     {
	      "name": "http",
	      "protocol": "TCP",
	      "port": 80
	     }
	   ],
	  "selector": {
	    "app": "nginx-gt" 
	   },
	  "type": "NodePort"
	 },
	"status": {
	  "loadBalancer": {}
	 }
}

注意:selector.app 为 Pod中label.app的值

Deployment 模版yaml文件

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2 # tells deployment to run 2 pods matching the template
  template: # create pods using pod definition in this template
    metadata:
      # unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is
      # generated from the deployment name
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

扫码关注微信公众号,更好的交流
扫码关注微信公众号,更好的交流

猜你喜欢

转载自blog.csdn.net/meifannao789456/article/details/89139703