1. Kubernetes 基本概念
1.1 Pod
Pod 是 Kubernetes 中最小的调度单元,它可以包含一个或多个容器。这些容器共享网络和存储,通常一起运行。
1.2 Deployment
Deployment 用于定义和管理 Pod 的部署,确保在集群中的副本数保持期望值。它还允许滚动更新应用程序。
1.3 Service
Service 定义了一组 Pod 的逻辑集合,并为这些 Pod 提供稳定的网络端点。Service 允许其他应用通过 Service 名称访问它们。
1.4 Node
Node 是 Kubernetes 集群中的工作节点,负责运行应用程序的容器。集群可以包含多个 Node。
1.5 Namespace
Namespace 是一种将 Kubernetes 集群划分为多个虚拟集群的方式。它允许不同的团队或项目在同一个集群上运行,而不会互相干扰。
2. 安装和配置 Kubernetes
Kubernetes 可以在本地环境或云上进行安装。以下是一个简单的本地安装示例,使用 Minikube:
2.1 安装 Minikube
# 安装 Minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# 启动 Minikube 集群
minikube start
2.2 安装 kubectl
# 安装 kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
sudo install kubectl /usr/local/bin/kubectl
3. 基本操作
3.1 创建 Deployment
kubectl create deployment hello-world --image=gcr.io/google-samples/hello-app:1.0
3.2 检查 Pod 状态
kubectl get pods
3.3 创建 Service
kubectl expose deployment hello-world --type=NodePort --port=8080
3.4 获取 Service URL
minikube service hello-world --url
3.5 扩展 Deployment
kubectl scale deployment hello-world --replicas=3
4. 清理和删除
4.1 删除 Service
kubectl delete service hello-world
4.2 删除 Deployment
kubectl delete deployment hello-world
4.3 停止 Minikube
minikube stop
这只是 Kubernetes 的入门指南,帮助你开始使用这个强大的容器编排平台。深入学习和使用 Kubernetes,你可能需要了解更多概念,例如 ConfigMap、Secret、Ingress 等。可以通过查阅 [Kubernetes 官方文档](https://kubernetes.io/docs/) 获取更详细的信息。
转载请注明出处:http://www.zyzy.cn/article/detail/9660/Kubernetes