记录java应用部署到k8s中
最近任务是把之前运行在docker里的自己写的java镜像部署到k8s中,踩了一些坑,记录如下:1.在写yaml文件时指定非shell命令而是一些命令行的时候要加上bash -c否则会报错:exec:“bash”:executable file not found in $PATH2.如果要操作容器里/etc/hosts这样的文件,会报错: can’t move ‘/etc/resolv.conf
·
最近任务是把之前运行在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
更多推荐
已为社区贡献6条内容
所有评论(0)