美文网首页
Kubernetes ( K8S ) 初始化容器与容器间共享数据

Kubernetes ( K8S ) 初始化容器与容器间共享数据

作者: Hello泽泽 | 来源:发表于2020-04-26 19:21 被阅读0次
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name:  zeze-test
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: zeze-test
      template:
        metadata:
          labels:
            app: zeze-test
        spec:
          
          # 第1个容器,初始化容器,创建一个html页面
          initContainers: 
          - name: alpine-write
            image: alpine
            volumeMounts:
            - name: zeze-test
              mountPath: /data 
              readOnly: false
            command:
              - sh
              - -c
              - " echo 'Hello, www.linuxhub.cn.' > /data/index.html "
    
        # 第 2 个容器,业务容器
          containers:
          - name: nignx 
            image: linuxhub/nginx:1.15.5
            ports:
            - containerPort: 80
            volumeMounts:
            - name: zeze-test
              mountPath: /usr/share/nginx/html 
              readOnly: true
          
    
         # 共同挂载使用的卷
          volumes:
          - name: zeze-test 
            emptyDir: {}
    
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: zeze-test
    spec:
      selector:
        app: zeze-test
      ports:
        - protocol: TCP
          port: 80
    
    --- 
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: zeze-test
    spec:
      rules:
      - host: k8s-test.linuxhub.cn
        http:
          paths:
          - backend:
              serviceName: zeze-test
              servicePort: 80
            path: /
    
    $ curl http://k8s-test.linuxhub.cn/index.html                                                                                                                           130 ↵
    Hello, www.linuxhub.cn.
    

    相关文章

      网友评论

          本文标题:Kubernetes ( K8S ) 初始化容器与容器间共享数据

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