zoukankan      html  css  js  c++  java
  • kubernetes(k8s)之K8s部署多种服务yaml文件

    nginx

     nginx-rc.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: nginx-controller
      labels:
        name: nginx
    spec:
      replicas: 2
      selector:
        name: nginx
      template:
        metadata:
          labels: 
           name: nginx
        spec:
          containers:
          - name: nginx
            image: docker.io/blacklabelops/nginx
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 80

    nginx-svc.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels: 
       name: nginx-servcie
    spec:
      type: NodePort
      ports:
      - port: 8000
        protocol: TCP
        targetPort: 80
        nodePort: 30088
      selector:
        name: nginx

    mysql

    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
                      ports:
                          - containerPort: 3306
                      env:
                          - name: MYSQL_ROOT_PASSWORD
                            value: "123456"

    mysql-svc.yaml

    apiVersion: v1                      
    kind: Service                              #表明是K8s Service
    metadata: 
      name: mysql                              #Service的全局唯一名称
    spec:
      ports:
        - port: 3306                           #Service提供服务的端口号
      selector:                                #Service对应的Pod拥有这里定义的标签
        app: mysql

    myweb

    myweb-rc.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: myweb
    spec:
      replicas: 1                                       #Pod副本期待数量为5
      selector:
        app: myweb
      template:
        metadata:
          labels:
            app: myweb
        spec:
          containers:
          - name: myweb
            image: kubeguide/tomcat-app:v1
            ports:
            - containerPort: 8080
            env:
            - name: MYSQL_SERVICE_HOST
              value: "mysql"
            - name: MYSQL_SERVICE_PORT
              value: "3306"

    myweb-svc.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: myweb
    spec:
       type: NodePort
       ports:
        - port: 8080
          nodePort: 31111
       selector:
          app: myweb
  • 相关阅读:
    sa-token v1.9.0 版本已发布,带来激动人心新特性:同端互斥登录
    为什么类只能用public修饰?
    Sentinel导航
    Ribbon导航
    Feign导航
    Gateway导航
    Nacos导航
    Nginx导航
    微服务导航
    Springboot之登录模块探索(含Token,验证码,网络安全等知识)
  • 原文地址:https://www.cnblogs.com/strive-man/p/10846604.html
Copyright © 2011-2022 走看看