Kubernetes(简称K8s)是一个开源的容器编排平台,用于自动化部署、扩展和管理容器化应用程序。本教程将为您介绍K8s的基本概念和操作步骤。

基本概念

  • Pod: K8s中的最小部署单元,包含一个或多个容器。
  • Service: 用于访问Pod的抽象层,定义了Pod的访问方式。
  • Deployment: 用于管理Pod的副本数量,保证Pod的健康状态。

快速开始

  1. 安装Docker
    • Ubuntu: sudo apt-get install docker.io
    • CentOS: sudo yum install docker
  2. 安装Kubernetes
  3. 创建一个简单的Pod
    • 使用以下命令创建一个名为 hello-world 的Pod:
      kubectl run hello-world --image=nginx
      
    • 查看Pod状态:
      kubectl get pods
      
  4. 访问Pod
    • 执行以下命令查看Pod的IP地址:
      kubectl get pod hello-world -o jsonpath='{.status.podIP}'
      
    • 使用浏览器访问Pod的IP地址,即可看到Nginx的欢迎页面。

图像教程

Kubernetes Pod

Kubernetes Service

Kubernetes Deployment

扩展阅读