7. 在 Kubernetes 集群中部署 ReplicaSet

发布: (2026年2月17日 GMT+8 10:30)
2 分钟阅读
原文: Dev.to

Source: Dev.to

实验信息

Nautilus DevOps 团队正在为迁移准备在 Kubernetes 集群上部署应用。任务之一是创建一个满足以下规格的 ReplicaSet:

  • 镜像: httpd:latest
  • ReplicaSet 名称: httpd-replicaset
  • 标签: app=httpd_apptype=front-end
  • 容器名称: httpd-container
  • 副本数量: 4

注意:jump_host 上的 kubectl 工具已经配置好,可与 Kubernetes 集群交互。

ReplicaSet 清单 (httpd-replicaset.yaml)

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: httpd-replicaset
  labels:
    app: httpd_app
    type: front-end
spec:
  replicas: 4
  selector:
    matchLabels:
      app: httpd_app
      type: front-end
  template:
    metadata:
      labels:
        app: httpd_app
        type: front-end
    spec:
      containers:
      - name: httpd-container
        image: httpd:latest
        ports:
        - containerPort: 80

应用 ReplicaSet

kubectl apply -f httpd-replicaset.yaml

验证部署

  • 检查 ReplicaSet 是否已创建

    kubectl get replicaset httpd-replicaset
  • 列出 ReplicaSet 创建的 Pods

    kubectl get pods
  • 获取关于 ReplicaSet 的详细信息

    kubectl describe replicaset httpd-replicaset

资源与后续步骤

致谢

  • 所有实验均来自 KodeKloud
0 浏览
Back to Blog

相关文章

阅读更多 »