本文将带你快速入门 Kubernetes,通过一个简单的 "Hello World" 示例,了解 Kubernetes 的一些基本概念。

什么是 Kubernetes?

Kubernetes 是一个开源的容器编排平台,用于自动化部署、扩展和管理容器化应用程序。

Hello World 示例

以下是一个简单的 Kubernetes Deployment 示例,用于运行一个包含 "Hello World" 的容器。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world-container
        image: nginx:latest
        ports:
        - containerPort: 80

创建 Deployment

  1. 将上述 YAML 内容保存为 hello-world-deployment.yaml
  2. 使用 kubectl apply -f hello-world-deployment.yaml 命令应用该配置。

访问服务

当 Deployment 创建完成后,你可以使用以下命令访问 "Hello World" 服务:

kubectl get endpoints

在输出的结果中,找到 hello-world 的 IP 地址,然后通过浏览器访问它。

更多内容

想要了解更多关于 Kubernetes 的知识,可以访问我们的 Kubernetes 教程 页面。


Kubernetes