美文网首页
Kubernetes权威指南 从一个简单的例子开始

Kubernetes权威指南 从一个简单的例子开始

作者: jinbulee | 来源:发表于2020-09-29 17:57 被阅读0次

    1、MySQL

    1.1创建mysql 的rc

    mysql-rc.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: mysql
    spec:
      replicas: 1
      selector:
        app: mysql
      template:
        metadata:
          labels:
            app: mysql
        spec:
          containers:
          - name: mysql
            image: mysql:5.6
            ports:
            - containerPort: 3306
            env:
            - name : MYSQL_ROOT_PASSWORD
              value: "123456"
    

    1.2 创建MySQL的svc

    mysql-svc.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: mysql
    spec:
      ports:
        - port: 3306
      selector:
        app: mysql
    

    2、myweb

    2.1创建myweb的rc

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: myweb
    spec:
      replicas: 1
      selector:
        app: myweb
      template:
        metadata:
          labels:
            app: myweb
        spec:
          containers:
            - name: myweb
              image: kubeguide/tomcat-app:v1
              ports:
              - containerPort: 8080
              env:
              - name: MYSQL_SERVICE_PORT
                value: '3306'
    
    

    2.2 创建myweb的svc

    myweb-svc.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: myweb
    spec:
      type: NodePort
      ports:
      - port: 8080
        nodePort: 30001
      selector:
        app: myweb
    

    然后浏览器访问 http://ip:30001/demo/

    image.png

    相关文章

      网友评论

          本文标题:Kubernetes权威指南 从一个简单的例子开始

          本文链接:https://www.haomeiwen.com/subject/abgeuktx.html