Kubernetes 是一种让使用者管理Cluster 的一种工具,能更轻松的管理node。本身提供Service Discovery 与 load-balance 的功能,像是自动配置IP等等。此外也提供进一步的操作,如设定记忆体限制、资料映射的区域等等。但更重要的事情是提供Self-healing 与Automated rollouts and rollbacks,让正在运行的node 可以自动的上下线,甚至可以自行修复node。
是在kubernetes 中最小单位,一个Pod指的是一个小的服务集,换句话说Pod 包含许多的container即微服务,但一个pod 不代表是一个Node。若是对比 docker 生态系,Pod 类似 docker-compose,可设定记忆体配置、mount disk 、cpu 数量等等,且都是透过yaml档案进行设置。
Pod 可以想成 group of container
Pod ymal 档案主要有几个必填项目[1]:
apiVersion
- Which version of the Kubernetes API you're using to create this objectkind
- What kind of object you want to createmetadata
- Data that helps uniquely identify the object, including a name
string, UID
, and optional namespace
spec
- What state you desire for the object那一般来说一个Pod 的设定档会包含两个Object, spec、status
这两个Object,spec 主要是定义Pod 有哪些container运行与设定,status
主要是提供Pod状态让 controller (control plane)去更新、撤销[2]。换句话说spec 是在 yaml 档案进行设定Pod的状态,然而status则是需透过 api或者cmd的方式读取目前Pod 的状态。
例如下列 nginx 范例。
apiVersion: v1
kind: Pod
metadata:
name: nginx-demo
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
由於k8s 本身的硬体需求比较庞大,因此各家机构纷纷推出自己的k8s开放工具,如Ubuntu基金会的Micro-K8s 或者 Rancher 的 k3s...等等,本范例使用k3s 进行解说,测试环境作业系统为ubuntu 20.04。
Attachment demo.yml
apiVersion: v1
kind: Pod
metadata:
name: nginx-demo
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
step 1.安装k3s
// install k3s
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=latest sh -
step 2.执行demo.yml 档案
sudo kubectl apply -f demo.yml
step 3.取得status
sudo kubectl get pod/nginx-demo -o yaml
[1] https://kubernetes.io/docs/home/
[2] https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
[3] https://rancher.com/docs/k3s/latest/
今天我们来练习制作一个可互动的 Spotify Sign-in 低精度原型吧! 首先,用昨天教学的...
前言 大家好,介绍完笔者团队的控制自走车研究後,今天我们则要来介绍如何在 Gazebo 世界中取得我...
昨天我们提到这个游戏共有五个关卡,接下来今天要依照关卡分别介绍我们的角色故事 肥遗 某一个村庄莫名闹...
变数 JS目前有三种宣告变数的方法。 在ES5以前都用var,ES6之後推出let与const。 新...
import React , {useState} from 'react'; const For...