当前位置:   article > 正文

记录java应用部署到k8s中_sed: can't move '/etc/resolv.confoiemka' to '/etc/

sed: can't move '/etc/resolv.confoiemka' to '/etc/resolv.conf': resource bus

最近任务是把之前运行在docker里的自己写的java镜像部署到k8
s中,踩了一些坑,记录如下:
1.在写yaml文件时指定非shell命令而是一些命令行的时候要加上bash -c否则会报错:exec:“bash”:executable file not found in $PATH
2.如果要操作容器里/etc/hosts这样的文件,会报错: can’t move ‘/etc/resolv.conf73UqmG’ to ‘/etc/resolv.conf’: Device or resource busy,一定要记着操作方式,如果用sed命令会报错,因为sed命令会重新拷贝一份,具体参考:https://www.cnblogs.com/xuxinkun/p/7116737.html
最后通过bash -c的方式往hosts文件里加域名:(因为openjdk:8-jdk-alpine只有sh没有bash,所以使用sh)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: java-data-store
  labels:
    app: java-data-store
spec:
  replicas: 1
  selector:
    matchLabels:
      app: java-data-store
  template:
    metadata:
      labels:
        app: java-data-store
    spec:
      containers:
      - name: java-data-store
        image: harbor:9501/library/openjdk:8-jdk-alpine
        imagePullPolicy: IfNotPresent
        ports:
        - name: data-store
          containerPort: 40502
        command: ["java", "-jar","jars/data-store.jar"]
        lifecycle:
          postStart:
            exec:
              command: ["sh","-c","echo 'xx.xx.xx.xx xxxx' >> /etc/hosts"]
        env:
        volumeMounts:
        - name: jar-vol
          mountPath: /jars
        - name: log-vol
          mountPath: app/logs
      restartPolicy: Always
      volumes:
      - name: jar-vol
        glusterfs:
          endpoints: glusterfs-cluster
          path: gv0/userapp/java-apps/jars
          readOnly: false
      - name: log-vol
        glusterfs:
          endpoints: glusterfs-cluster
          path: gv0/userapp/java-apps/logs/data-store
          readOnly: false
---
apiVersion: v1
kind: Service
metadata:
  name: java-data-store
spec:
  selector:
    app: java-data-store
  ports:
    - port: 40502
      targetPort: 40502
      nodePort: 30203
  type: NodePort
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/424792
推荐阅读
相关标签
  

闽ICP备14008679号