One, POD understanding
Docker schedules containers. In a k8s cluster, the smallest scheduling unit is Pod. There can be one container or multiple containers in a POD, but in business use, it is usually split into one POD for application and one POD for database to achieve Effective security and resource distribution management.
Two, use yaml format to define POD
#一个POD包含两个容器
apiVersion: v1 #该Pod的版本信息,可通过命令查看
kind: Pod #创建一个pod的资源
metadata:
name: myblog #该pod资源的名称
namespace: luffy #该pod资源的命名空间
labels:
component: myblog #该pod资源的label标签归属
spec: #为该pod资源定义精确的信息
containers: #定义为容器
- name: myblog #第一个容器的名称
image: 10.3.153.200:5000/myblog:v1 #容器的镜像拉取
env: #该容器内的环境变量传输
- name: MYSQL_HOST
value: "127.0.0.1" #因一个pod下的容器,可直接访问本地数据库
- name: MYSQL_PASSWD
value: "123456"
ports: #容器定义发布端口,类同于expose
- containerPort: 8002
- name: mysql #第二个容器的名称
image: 10.3.153.200:5000/mysql:5.7-utf8
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
- name: MYSQL_DATABASE
value: "myblog"
apiVersion: v1 (version meaning)
kind: Pod (all resources of K8S can be viewed through the following command)
metadata
帮助唯一性标识对象的一些数据,包括一个 name 字符串、UID 和可选的 namespace、labels标签
spec
对象 spec 的精确格式对每个 Kubernetes 对象来说是不同的,包含了特定于该对象的嵌套字段
containers
定义该POD下的容器信息,如容器名称、镜像、端口、磁盘等等信息