k8s-中间件yaml

Nginx

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    k8s-app: nginx
spec:
  replicas: 1  
  selector:
    matchLabels:
      k8s-app: nginx
  template:
    metadata:
      labels:
        k8s-app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.23.3
        ports:
        #容器的端口
        - containerPort: 80
          name: nginx
          protocol: TCP          
        volumeMounts:
        - mountPath: /etc/localtime
          name: tz
          readOnly: true    
        - mountPath: /usr/share/fonts/truetype/dejavu
          name: fonts
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: tz
      - hostPath:
          path: /usr/share/fonts/dejavu
          type: Directory
        name: fonts
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    k8s-app: nginx
spec:
  ports:
  #集群IP的端口
  - port: 80
    name: nginx
    protocol: TCP
    #容器的端口
    targetPort: 80
  selector:
    k8s-app: nginx
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: nginx-http
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`nginx.test.com`) && PathPrefix(`/`)
    kind: Rule
    services:
    - name: nginx
      port: 80

MySQL

注意修改以下:

  • 名称空间(namespace)
  • 存储(storageClassName)
  • 端口(nodePort)–默认:30306
  • 副本数(replicas)–默认:1
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-cnf
  namespace: demo
data:
  my.cnf: |-
    [client]
    default-character-set=utf8mb4

    [mysql]
    default-character-set=utf8mb4

    [mysqld]
    init_connect='SET collation_connection = utf8mb4_unicode_ci'
    init_connect='SET NAMES utf8mb4'
    character-set-server=utf8mb4
    collation-server=utf8mb4_unicode_ci
    skip-character-set-client-handshake
    skip-name-resolve
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: demo-mysql
  namespace: demo
  labels:
    app: demo-mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo-mysql
  serviceName: demo-mysql-v7fa
  template:
    metadata:
      labels:
        app: demo-mysql
    spec:
      containers:
      - env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"
        image: mysql:5.7.38
        imagePullPolicy: IfNotPresent
        name: mysql
        ports:
        - containerPort: 3306
          name: tcp-3306
          protocol: TCP
        - containerPort: 33060
          name: tcp-33060
          protocol: TCP
        resources:
          limits:
            cpu: "1"
            memory: 2Gi
        volumeMounts:
        - mountPath: /etc/localtime
          name: host-time
        - mountPath: /var/lib/mysql
          name: mysql
        - mountPath: /etc/mysql/conf.d
          name: volume-kpcl83
          readOnly: true
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: host-time
      - configMap:
          defaultMode: 420
          name: mysql-cnf
        name: volume-kpcl83
  volumeClaimTemplates:
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: mysql
      namespace: demo
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
      storageClassName: nfs-storage
      volumeMode: Filesystem
---
apiVersion: v1
kind: Service
metadata:
  name: demo-mysql-v7fa
  namespace: demo
  labels:
    app: demo-mysql
spec:
  clusterIP: None
  clusterIPs:
  - None
  ports:
  - name: tcp-3306
    port: 3306
    protocol: TCP
    targetPort: 3306
  - name: tcp-33060
    port: 33060
    protocol: TCP
    targetPort: 33060
  selector:
    app: demo-mysql
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-extra
  namespace: demo
  labels:
    app: mysql-extra
spec:
  selector:
    app: demo-mysql
  type: NodePort
  ports:
  - name: http-3306
    nodePort: 30306
    port: 3306
    protocol: TCP
    targetPort: 3306

Redis

注意修改以下:
● 名称空间(namespace)
● 存储(storageClassName)
● 端口(nodePort)–默认:31991
● 副本数(replicas)–默认:1

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-conf
  namespace: demo
data:
  redis.conf: |-
    appendonly yes
    port 6379
    bind 0.0.0.0
    requirepass 123456
---
apiVersion: v1
kind: Service
metadata:
  name: redis-demo-l15p
  namespace: demo
  labels:
    app: redis-demo
spec:
  clusterIP: None
  clusterIPs:
  - None
  ports:
  - name: tcp-6379
    port: 6379
    protocol: TCP
    targetPort: 6379
  selector:
    app: redis-demo
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  name: redis-extral
  namespace: demo
  labels:
    app: redis-extral
spec:
  ports:
  - name: http-6379
    nodePort: 31991
    port: 6379
    protocol: TCP
    targetPort: 6379
  selector:
    app: redis-demo
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis-demo
  namespace: demo
  labels:
    app: redis-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-demo
  serviceName: redis-demo-l15p
  template:
    metadata:
      labels:
        app: redis-demo
    spec:
      containers:
      - args:
        - /etc/redis/redis.conf
        command:
        - redis-server
        image: redis:5.0.14
        imagePullPolicy: IfNotPresent
        name: redis-demo
        ports:
        - containerPort: 6379
          name: tcp-6379
          protocol: TCP
        resources:
          limits:
            cpu: "1"
            memory: 1000Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/localtime
          name: host-time
        - mountPath: /data
          name: redis-demo
        - mountPath: /etc/redis
          name: volume-6yl41w
          readOnly: true
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: host-time
      - configMap:
          defaultMode: 420
          name: redis-conf
        name: volume-6yl41w
  volumeClaimTemplates:
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: redis-demo
      namespace: demo
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
      storageClassName: nfs-storage
      volumeMode: Filesystem

Elasticsearch

apiVersion: v1
kind: ConfigMap
metadata:
  name: es-conf
  namespace: demo
data:
  elasticsearch.yml: |-
    cluster.name: "docker-cluster"
    network.host: 0.0.0.0
  jvm.options: |-
    ################################################################
    ##
    ## JVM configuration
    ##
    ################################################################
    ##
    ## WARNING: DO NOT EDIT THIS FILE. If you want to override the
    ## JVM options in this file, or set any additional options, you
    ## should create one or more files in the jvm.options.d
    ## directory containing your adjustments.
    ##
    ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
    ## for more information.
    ##
    ################################################################



    ################################################################
    ## IMPORTANT: JVM heap size
    ################################################################
    ##
    ## The heap size is automatically configured by Elasticsearch
    ## based on the available memory in your system and the roles
    ## each node is configured to fulfill. If specifying heap is
    ## required, it should be done through a file in jvm.options.d,
    ## and the min and max should be set to the same value. For
    ## example, to set the heap to 4 GB, create a new file in the
    ## jvm.options.d directory containing these lines:
    ##
    ## -Xms4g
    ## -Xmx4g
    ##
    ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
    ## for more information
    ##
    ################################################################


    ################################################################
    ## Expert settings
    ################################################################
    ##
    ## All settings below here are considered expert settings. Do
    ## not adjust them unless you understand what you are doing. Do
    ## not edit them in this file; instead, create a new file in the
    ## jvm.options.d directory containing your adjustments.
    ##
    ################################################################

    ## GC configuration
    8-13:-XX:+UseConcMarkSweepGC
    8-13:-XX:CMSInitiatingOccupancyFraction=75
    8-13:-XX:+UseCMSInitiatingOccupancyOnly

    ## G1GC Configuration
    # NOTE: G1 GC is only supported on JDK version 10 or later
    # to use G1GC, uncomment the next two lines and update the version on the
    # following three lines to your version of the JDK
    # 10-13:-XX:-UseConcMarkSweepGC
    # 10-13:-XX:-UseCMSInitiatingOccupancyOnly
    14-:-XX:+UseG1GC

    ## JVM temporary directory
    -Djava.io.tmpdir=${ES_TMPDIR}

    ## heap dumps

    # generate a heap dump when an allocation from the Java heap fails; heap dumps
    # are created in the working directory of the JVM unless an alternative path is
    # specified
    -XX:+HeapDumpOnOutOfMemoryError

    # specify an alternative path for heap dumps; ensure the directory exists and
    # has sufficient space
    -XX:HeapDumpPath=data

    # specify an alternative path for JVM fatal error logs
    -XX:ErrorFile=logs/hs_err_pid%p.log

    ## JDK 8 GC logging
    8:-XX:+PrintGCDetails
    8:-XX:+PrintGCDateStamps
    8:-XX:+PrintTenuringDistribution
    8:-XX:+PrintGCApplicationStoppedTime
    8:-Xloggc:logs/gc.log
    8:-XX:+UseGCLogFileRotation
    8:-XX:NumberOfGCLogFiles=32
    8:-XX:GCLogFileSize=64m

    # JDK 9+ GC logging
    9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
---
apiVersion: v1
kind: Service
metadata:
  name: es-demo-8hs8
  namespace: demo
  labels:
    app: es-demo
spec:
  clusterIP: None
  clusterIPs:
  - None
  ports:
  - name: tcp-9200
    port: 9200
    protocol: TCP
    targetPort: 9200
  - name: tcp-9300
    port: 9300
    protocol: TCP
    targetPort: 9300
  selector:
    app: es-demo
  sessionAffinity: None
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  name: es-extral
  namespace: demo
  labels:
    app: es-extral
spec:
  ports:
  - name: http-9200
    nodePort: 32520
    port: 9200
    protocol: TCP
    targetPort: 9200
  - name: http-9300
    nodePort: 32103
    port: 9300
    protocol: TCP
    targetPort: 9300
  selector:
    app: es-demo
  sessionAffinity: None
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-demo
  namespace: demo
  labels:
    app: es-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: es-demo
  serviceName: es-demo-8hs8
  template:
    metadata:
      labels:
        app: es-demo
    spec:
      containers:
      - env:
        - name: discovery.type
          value: single-node
        - name: ES_JAVA_OPTS
          value: -Xms512m -Xmx512m
        image: elasticsearch:7.13.4
        imagePullPolicy: IfNotPresent
        name: elasticsearch
        ports:
        - containerPort: 9200
          name: tcp-9200
          protocol: TCP
        - containerPort: 9300
          name: tcp-9300
          protocol: TCP
        resources:
          limits:
            cpu: "2"
            memory: 1000Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/localtime
          name: host-time
        - mountPath: /usr/share/elasticsearch/data
          name: es-demo
        - mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          name: volume-r7u37l
          readOnly: true
          subPath: elasticsearch.yml
        - mountPath: /usr/share/elasticsearch/config/jvm.options
          name: volume-rj7sxj
          readOnly: true
          subPath: jvm.options
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: host-time
      - configMap:
          defaultMode: 420
          items:
          - key: elasticsearch.yml
            path: elasticsearch.yml
          name: es-conf
        name: volume-r7u37l
      - configMap:
          defaultMode: 420
          items:
          - key: jvm.options
            path: jvm.options
          name: es-conf
        name: volume-rj7sxj
  volumeClaimTemplates:
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: es-demo
      namespace: demo
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
      storageClassName: nfs-storage
      volumeMode: Filesystem

RabbitMQ

apiVersion: v1
kind: ConfigMap
metadata:
  name: rabbitm-hhxed8-rabbitmq
  namespace: demo
  labels:
    app.kubernetes.io/instance: rabbitm-hhxed8
    app.kubernetes.io/name: rabbitmq
data:
  advanced.config: |
    [
      {rabbitmq_auth_backend_ldap, [
        %% Authorisation
      ]}
    ].
  enabled_plugins: |
    [
      rabbitmq_management
    ].
  rabbitmq.conf: |
    loopback_users.guest = false
    default_user = admin
    default_pass = admin
    ## Number of Erlang processes that will accept connections for the TCP
    ## and TLS listeners.
    ##
    # num_acceptors.tcp = 10
    # num_acceptors.ssl = 10

---
kind: Service
apiVersion: v1
metadata:
  name: rabbitm-hhxed8-rabbitmq
  namespace: demo
  labels:
    app.kubernetes.io/instance: rabbitm-hhxed8
    app.kubernetes.io/name: rabbitmq
spec:
  ports:
    - name: amqp
      protocol: TCP
      port: 5672
      targetPort: amqp
    - name: management
      protocol: TCP
      port: 15672
      targetPort: management
  selector:
    app.kubernetes.io/instance: rabbitm-hhxed8
    app.kubernetes.io/name: rabbitmq
  type: ClusterIP
---
kind: Service
apiVersion: v1
metadata:
  name: rabbitmq-demo
  namespace: demo
  labels:
    app: rabbitmq-demo
spec:
  ports:
    - name: http-15672
      protocol: TCP
      port: 15672
      targetPort: 15672
      nodePort: 30520
  selector:
    app.kubernetes.io/instance: rabbitm-hhxed8
    app.kubernetes.io/name: rabbitmq
  type: NodePort
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: rabbitm-hhxed8-rabbitmq
  namespace: demo
  labels:
    app.kubernetes.io/instance: rabbitm-hhxed8
    app.kubernetes.io/name: rabbitmq
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/instance: rabbitm-hhxed8
      app.kubernetes.io/name: rabbitmq
  template:
    metadata:
      labels:
        app.kubernetes.io/instance: rabbitm-hhxed8
        app.kubernetes.io/name: rabbitmq
    spec:
      volumes:
        - name: conf
          configMap:
            name: rabbitm-hhxed8-rabbitmq
            defaultMode: 420
      containers:
        - name: rabbitmq
          image: 'rabbitmq:3.8.11-management-alpine'
          ports:
            - name: amqp
              containerPort: 5672
              protocol: TCP
            - name: management
              containerPort: 15672
              protocol: TCP
          resources: {}
          volumeMounts:
            - name: data
              mountPath: /var/lib/rabbitmq/mnesia
            - name: conf
              mountPath: /etc/rabbitmq
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
  volumeClaimTemplates:
    - kind: PersistentVolumeClaim
      apiVersion: v1
      metadata:
        name: data
        labels:
          app.kubernetes.io/instance: rabbitm-hhxed8
          app.kubernetes.io/name: rabbitmq
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 5Gi
        volumeMode: Filesystem
  serviceName: rabbitm-hhxed8-rabbitmq
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值