k8s启动wordpress服务

这是wordpress-Deployement.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
spec:
  replicas: 2
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
      - name: wordpress
        image: 10.18.4.10/library/wordpress:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /src
          name: cache-volume

      - name: mysql
        image: 10.18.4.10/library/mysql:5.6
        ports:
        - containerPort: 3306
        volumeMounts:
        - mountPath: /src
          name: cache-volume
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: wordpress
        - name: MYSQL_DATABASE
          value: wordpress

      volumes:
      - name: cache-volume
        hostPath:
          path: /etc
          type: Directory

Job,DeploymentReplica Set,和Daemon Set,支持set-based要求。

selector:
  matchLabels:
    component: redis
  matchExpressions:
    - {key: tier, operator: In, values: [cache]}
    - {key: environment, operator: NotIn, values: [dev]}

matchLabels 是一个{key,value}的映射。一个单独的 {key,value} 相当于 matchExpressions 的一个元素,它的key字段是”key”,操作符是 In ,并且value数组value包含”value”。 matchExpressions 是一个pod的选择器条件的list 。有效运算符包含In, NotIn, Exists, 和DoesNotExist。在In和NotIn的情况下,value的组必须不能为空。所有的条件,包含 matchLabels andmatchExpressions 中的,会用AND符号连接,他们必须都被满足以完成匹配。

apiVersion: apps/v1					#接口版本 必选,版本号,例如v1
kind: Deployment					#接口类型
metadata:							#是该资源的元数据,name 是必需的元数据项
  name: wordpress					#Deployment名称
spec:								#spec 部分是该 Deployment 的规格说明
  replicas: 2						#replicas 指明副本数量,默认为 1						
  selector:
    matchLabels:
      app: wordpress
  template:							#template 定义 Pod 的模板,这是配置文件的重要部分
    metadata:						#metadata 定义 Pod 的元数据,至少要定义一个 label。label 的 key 和 value 可以任意指定
      labels:
        app: wordpress				#模板名称必填
    spec:							#定义容器模板,该模板可以包含多个容器
      containers:					
      - name: wordpress				#镜像名称				
        image: 192.168.200.8/library/wordpress:latest	#镜像名称
        ports:						#需要暴露的端口库号列表
        - containerPort: 80			#容器需要监听的端口号			
        volumeMounts:				#挂载到容器内部的存储卷配置【挂载volumes中定义的磁盘】
        - mountPath: /abc			#存储卷在容器内mount的绝对路径,应少于512字符
          name: cache-volume		#直接挂载硬盘方法,如挂载下面的/abc目录

      - name: mysql
        image: 192.168.200.8/library/mysql:5.6
        ports:
        - containerPort: 3306
        volumeMounts:
        - mountPath: /abc
          name: cache-volume
        env:						#容器运行前需设置的环境变量列表
        - name: MYSQL_ROOT_PASSWORD	#环境变量名称
          value: wordpress			#环境变量的值
        - name: MYSQL_DATABASE
          value: wordpress
      
      volumes:
      - name: cache-volume
        hostPath:
          path: /etc
          type: Directory

这是wordpress-Services.yaml

apiVersion: v1
kind: Service
metadata:
  name: wordpress-svc
spec:
  type: NodePort
  ports:
  - name: wordpress
    port: 80
    targetPort: 80
    nodePort: 30001
  - name: mysql
    port: 3306
    targetPort: 3306
    nodePort: 30002
  selector:
    app: wordpress

猜你喜欢

转载自blog.csdn.net/m0_52426915/article/details/116003491
k8s