Pod多容器运行,环境变量传递,镜像下载策略,镜像拉取策略,容器资源限制,端口映射及故障排查命令基础
- 资源清单编写,需要使用"kubectl explain"文档查看,及官方文档查看说明;
- 环境变量传递
- 多容器启动
- 镜像下载策略
- 容器重启策略
- 资源限制
- 端口映射
- K8S故障排查技巧
- 容器的类型:
- 基础架构容器
- 业务容器
- 初始化容器
在K8S集群部署MySQL服务 demon
cat 03-pods-wordpress.yaml
apiVersion: v1
kind: Pod
metadata:
name: baimei-wp
spec:
containers:
- name: db
image: harbor.baimei.com/baimei-db/mysql:5.7
# 向容器传递环境变量
env:
# 变量的名称
- name: MYSQL_ALLOW_EMPTY_PASSWORD
# 指定变量的值
value: "yes"
- name: MYSQL_DATABASE
value: "wordpress"
- name: MYSQL_USER
value: "admin"
- name: MYSQL_PASSWORD
value: "baimei"
3.创建资源
kubectl apply -f 03-pods-wordpress.yaml
4.查看资源
kubectl get pods
5.验证Pod
kubectl exec -it baimei-wp -- mysql
二、端口映射
apiVersion: v1
kind: Pod
metadata:
name: baimei-ports-01
spec:
# hostNetwork: true
nodeName: worker233
containers:
- name: db
image: harbor.baimei.com/baimei-db/mysql:5.7
# 指定pod的端口映射信息
ports:
# 容器的端口号
- containerPort: 3306
# 容器绑定到宿主机的IP地址,若不写表示"0.0.0.0"
hostIP: 10.0.0.233
# 映射的主机端口
hostPort: 13306
# 给服务起名字,要求唯一
name: db
# 指定协议
protocol: TCP
#- containerPort: 80
# hostIP: 10.0.0.233
# hostPort: 18080
# name: wp
env:
- name: MYSQL_ALLOW_EMPTY_PASSWORD
value: "yes"
- name: MYSQL_DATABASE
value: "wordpress"
- name: MYSQL_USER
value: "admin"
- name: MYSQL_PASSWORD
value: "baimei"
- name: wp
image: harbor.baimei.com/baimei-wordpress/wordpress:latest
env:
- name: WORDPRESS_DB_HOST
value: "127.0.0.1"
- name: WORDPRESS_DB_USER
value: "admin"
- name: WORDPRESS_DB_PASSWORD
value: "baimei"
- name: WORDPRESS_DB_NAME
value: "wordpress"
ports:
- containerPort: 80
hostIP: 10.0.0.233
hostPort: 18080
name: wp
欢迎来撩 : 汇总all