Kubernetes 是一个开源的容器编排平台,用于自动化应用部署、扩展和管理。以下是 Kubernetes 入门指南,帮助您快速了解并开始使用 Kubernetes。
基础概念
- 容器 (Container):轻量级、可执行的软件包,包含应用程序及其运行环境。
- Pod:Kubernetes 工作负载的基本单元,包含一个或多个容器。
- 集群 (Cluster):一组节点组成的集群,节点可以是物理机或虚拟机。
- 部署 (Deployment):Kubernetes 的无状态应用部署和管理工具。
安装 Kubernetes
安装 Kubernetes 的具体步骤请参考 Kubernetes 安装指南。
快速上手
Hello World
apiVersion: v1 kind: Pod metadata: name: hello-world spec: containers: - name: hello-world-container image: busybox args: - /bin/sh - -c - echo Hello, world!
创建此配置文件,并将其保存为
hello-world.yaml
,然后使用以下命令创建 Pod:kubectl apply -f hello-world.yaml
查看 Pod 状态 使用以下命令查看 Pod 的状态:
kubectl get pods
访问应用 如果 Pod 配置了端口映射,您可以通过以下命令访问应用:
kubectl port-forward pod/hello-world 8080:80
打开浏览器访问
http://localhost:8080
,即可看到 Hello, world! 字样。
进一步学习
Kubernetes Architecture