惜风不起、唯有努力!
shell自动生成K8S资源

shell自动生成K8S资源

#!/bin/bash
#自动生成k8s的服务yaml

if [[ $# -lt 2 ]]; then
  echo "Usage: $0 <pod name> <image>"
  exit 1
fi

pod_name="$1"
image="$2"

cat <<EMO > ${pod_name}.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: $pod_name-dep
  namespace: web
  labels:
    app: $pod_name
spec:
  replicas: 1
  selector:
    matchLabels:
      app: $pod_name
  template:
    metadata:
      labels:
        app: $pod_name
    spec:
      terminationGracePeriodSeconds: 35
      containers:
      - name: $pod_name-images
        image: $image
        imagePullPolicy: IfNotPresent
        env:
        - name: DEMO_GREETING
          value: "my-env"
        ports:
        - containerPort: 80
          name: app-port
          protocol: TCP
        resources:
          limits:
            cpu: 200m
            memory: 500Mi
          requests:
            cpu: 100m
            memory: 200Mi
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 15
          timeoutSeconds: 5
          failureThreshold: 3
          successThreshold: 1
        readinessProbe:
          tcpSocket:
            port: 80
          initialDelaySeconds: 15
          timeoutSeconds: 5
          failureThreshold: 3
          successThreshold: 1
EMO
echo "Pod YAML file ${pod_name}.yaml generated successfully."

发表回复

您的电子邮箱地址不会被公开。