searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

K8S脚本--Kubernetes集群的资源限制

2025-03-13 16:48:48
1
0

#!/bin/bash

# 配置参数
NAMESPACE="default"
LIMITS_FILE="/path/to/resource_limits.yaml"
LOG_FILE="/var/log/k8s_resource_limits.log"

# 检查并创建日志文件
if [ ! -f "$LOG_FILE" ]; then
  touch "$LOG_FILE"
fi

# 记录日志函数
log() {
  echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" >> "$LOG_FILE"
}

# 检查资源限制文件是否存在
if [ ! -f "$LIMITS_FILE" ]; then
  log "Error: Resource limits file $LIMITS_FILE does not exist."
  exit 1
fi

# 应用资源限制
log "Applying resource limits to namespace $NAMESPACE..."
kubectl apply -f "$LIMITS_FILE" -n "$NAMESPACE"

if [ $? -eq 0 ]; then
  log "Resource limits applied successfully to namespace $NAMESPACE."
else
  log "Failed to apply resource limits to namespace $NAMESPACE. Please check the logs for details."
  exit 1
fi

# 检查资源限制是否生效
log "Checking resource limits status..."
kubectl describe limits -n "$NAMESPACE"

log "Resource limits setup completed successfully."

0条评论
0 / 1000
王****际
180文章数
2粉丝数
王****际
180 文章 | 2 粉丝
原创

K8S脚本--Kubernetes集群的资源限制

2025-03-13 16:48:48
1
0

#!/bin/bash

# 配置参数
NAMESPACE="default"
LIMITS_FILE="/path/to/resource_limits.yaml"
LOG_FILE="/var/log/k8s_resource_limits.log"

# 检查并创建日志文件
if [ ! -f "$LOG_FILE" ]; then
  touch "$LOG_FILE"
fi

# 记录日志函数
log() {
  echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" >> "$LOG_FILE"
}

# 检查资源限制文件是否存在
if [ ! -f "$LIMITS_FILE" ]; then
  log "Error: Resource limits file $LIMITS_FILE does not exist."
  exit 1
fi

# 应用资源限制
log "Applying resource limits to namespace $NAMESPACE..."
kubectl apply -f "$LIMITS_FILE" -n "$NAMESPACE"

if [ $? -eq 0 ]; then
  log "Resource limits applied successfully to namespace $NAMESPACE."
else
  log "Failed to apply resource limits to namespace $NAMESPACE. Please check the logs for details."
  exit 1
fi

# 检查资源限制是否生效
log "Checking resource limits status..."
kubectl describe limits -n "$NAMESPACE"

log "Resource limits setup completed successfully."

文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0