ITPub博客

首页 > 数据库 > 数据库开发技术 > kuerbnetes创建资源yaml参数说明完整版

kuerbnetes创建资源yaml参数说明完整版

原创 数据库开发技术 作者:步步运维步步坑 时间:2023-10-24 11:05:30 0 删除 编辑

参数说明

# Deployment配置

apiVersion: apps/v1

kind: Deployment

metadata:

  name: my-app-deployment # 部署的名称

spec:

  replicas: 3 # 副本数

  selector:  # 选择器

    matchLabels:  # 标签选择器

      app: my-app  # 标签名字

  template:  

    metadata: # 定义元数据

      labels:  # 标签

        app: my-app  # 标签名字

    spec:  

      containers: # 容器

        - name: my-app-container  # 容器名称

          image: my-app-image:latest # 容器的镜像

          ports: 

            - containerPort: 80 # 容器监听的端口

          resources: # 资源相关

            requests:  # 预请求资源

              memory: "64Mi"   # 容器的资源请求

              cpu: "250m"

            limits:  # 限制资源

              memory: "128Mi" # 容器的资源限制

              cpu: "500m"

          env:  # 环境变量

            - name: APP_ENV

              value: production # 容器环境变量

          livenessProbe:

            httpGet:

              path: /health    # 活跃探针

              port: 80            # 被监控端口

            initialDelaySeconds: 15  # 检测延后时间

            periodSeconds: 10    # 超时时间

          readinessProbe:

            httpGet:

              path: /readiness     # 可用性探针

              port: 80  # 被检测端口

            initialDelaySeconds: 5

            periodSeconds: 5

          volumeMounts:  # 数据卷

            - name: my-config-volume # 卷名称

              mountPath: /etc/config  # 挂载位置

            - name: my-secret-volume 

              mountPath: /etc/secret

# Service配置

apiVersion: v1

kind: Service

metadata:

  name: my-app-service # 服务的名称

spec:

  selector:

    app: my-app

  ports:

    - name: http

      port: 80   

      targetPort: 80 # 服务端口映射

  type: LoadBalancer


# Ingress配置

apiVersion: networking.k8s.io/v1

kind: Ingress

metadata:

  name: my-app-ingress # Ingress的名称

spec:

  rules:

    - host: my-app.example.com # 域名

      http:

        paths:

          - pathType: Prefix  

            path: /  # 规则路由

            backend:  # 后端服务 svc

              service:

                name: my-app-service

                port:

                  number: 80

# ConfigMap配置

apiVersion: v1

kind: ConfigMap

metadata:

  name: my-config # ConfigMap的名称

data:

  config-key: config-value # 配置数据

# Secret配置

apiVersion: v1

kind: Secret

metadata:

  name: my-secret # Secret的名称

type: Opaque

data:

  username: BASE64_ENCODED_USERNAME # 编码的用户名

  password: BASE64_ENCODED_PASSWORD # 编码的密码


# PersistentVolumeClaim配置

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

  name: my-pvc # PVC的名称

spec:

  accessModes:

    - ReadWriteOnce # 访问模式

  resources:

    requests:

      storage: 10Gi # 存储大小


# PersistentVolume配置

apiVersion: v1

kind: PersistentVolume

metadata:

  name: my-pv # PV的名称

spec:

  capacity:

    storage: 10Gi   # 存储大小

  accessModes:   # 卷模式

    - ReadWriteOnce

  hostPath:

    path: /data/my-app-data # PV的主机路径


更多配置可以参考命令

kubectl explain pod.spec.affinity.pod.xxxxx    # 按实际需求使用 explain后面的内容

认真做好每一件事

微信号|yfq940-

@

扫码关注我们


原文作者:步步运维步步坑;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论

注册时间:2022-10-08

  • 博文量
    100
  • 访问量
    51710