您的位置 首页 k8s

一个pod 内运行多个容器案例(不同节点)

一个pod 内运行多个容器案例(不同节点)

 

apiVersion: v1
kind: Pod
metadata:
  name: baimei-db
spec:
  # nodeName: worker232
  containers: 
  - name: db
    image: harbor.baimei.com/baimei-db/mysql:5.7
    ports:
    - containerPort: 3306
      name: db
    env:
    - name: MYSQL_ALLOW_EMPTY_PASSWORD
      value: "yes"
    - name: MYSQL_DATABASE
      value: "wordpress"
    - name: MYSQL_USER
      value: "admin"
    - name: MYSQL_PASSWORD
      value: "baimei"
# 实际运行Pod的状态
status:
  hostIP: 10.0.0.232


---

apiVersion: v1
kind: Pod
metadata:
  name: baimei-wp
spec:
  nodeName: worker233
  containers: 
  - name: wp
    image: harbor.baimei.com/baimei-wordpress/wordpress:latest
    env:
    - name: WORDPRESS_DB_HOST
      # 需要先创建MySQL数据库,然后修改ip地址,后期可以使用Service资源类型来自动发现Pod的IP
      value: "10.100.1.20"
    - name: WORDPRESS_DB_USER
      value: "admin"
    - name: WORDPRESS_DB_PASSWORD
      value: "baimei"
    - name: WORDPRESS_DB_NAME
      value: "wordpress"
    ports:
    - containerPort: 80
      hostPort: 18080
      name: wp

 

 

中间的 ---  必须要有的

 

获取 mysql  运行时的地址:

kubectl apply -f 08-pods-wp-mysql.yaml

kubectl get pods -o wide

 

kubectl delete pod baimei-wp

 

 

 

 

然后:

http://10.0.0.233:18080/wp-admin/install.php

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章