• k8s中部署wordpress


    使用一个pod的方式在k8s中部署wordpress

    wordpress至少需要的环境

    • 数据库
    • wordpress镜像

    vi wordpress.yaml

    apiVersion: v1
    kind: Namespace
    metadata:
      name: wordpress
    ---
    # 创建pod
    apiVersion: v1
    kind: Pod
    metadata:
      name: wordpress
      namespace: wordpress
      labels:
        app: wordpress    # <==== 这里添加一个label标签,pod 向外暴露pod的service NodePort型端口需要用标签选择器。
    spec:
      containers:
      - name: wordpress
        image: wordpress
        ports:
        - containerPort: 80
          name: wdport
        env:
        - name: WORDPRESS_DB_HOST
          value: 127.0.0.1:3306    # <==== 这里不能是localhost数据库的localhost默认是去找socket文件,然而在不同的容器之间文件系统是隔离的,会导致报错;
        - name: WORDPRESS_DB_USER
          value: wordpress
        - name: WORDPRESS_DB_PASSWORD
          value: wordpress
        imagePullPolicy: IfNotPresent 
      - name: mysql
        image: mysql:5.7
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3306
          name: dbport
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: dayi123
        - name: MYSQL_DATABASE
          value: wordpress
        - name: MYSQL_USER
          value: wordpress
        - name: MYSQL_PASSWORD
          value: wordpress
        volumeMounts:
        - name: db
          mountPath: /var/lib/mysql
      volumes:
        - name: db
          hostPath:
            path: /var/lib/mysql
    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: wordpress
      name: wp-svc
      namespace: wordpress
    spec:
      ports:
      - port: 8081
        protocol: TCP
        targetPort: 80
      selector:
        app: wordpress
      type: NodePort
    
    kubectl apply -f wordpress.yaml
    

  • 相关阅读:
    java-jdbc基础巩固
    webservice简单的编写,发布,调用
    HanLP笔记
    HanLP笔记
    HanLP笔记
    HanLP笔记
    Python学习小计
    R学习小计
    SPSS学习小记
    C语言学习小记
  • 原文地址:https://www.cnblogs.com/gshelldon/p/15785315.html
Copyright © 2020-2023  润新知