Here is the deployment file I write:
apiVersion: apps/v1
kind: Deployment
metadata:
name: setup
labels:
app: setup
spec:
replicas: 1
selector:
matchLabels:
app: setup
template:
metadata:
labels:
app: setup
spec:
containers:
- name: setup
image: esmagic/setup:1.0
ports:
- containerPort: 8081
---
apiVersion: v1
kind: Service
metadata:
name: setup
labels:
app: setup
spec:
ports:
- name: tcp-8081-8081-setup
port: 8081
targetPort: 8081
protocol: TCP
selector:
app: setup
type: LoadBalancer
externalIPs:
- 192.168.1.249
sessionAffinity: None
externalTrafficPolicy: Cluster
status:
loadBalancer: {}
For the first one, you have to define volume mounts in spec container and define volume in spec, and for second one you have to define public IP in external IPs
Deployment file after changes:
apiVersion: apps/v1
kind: Deployment
metadata:
name: setup
labels:
app: setup
spec:
replicas: 1
selector:
matchLabels:
app: setup
template:
metadata:
labels:
app: setup
spec:
containers:
- name: setup
image: esmagic/setup:1.0
ports:
- containerPort: 8081
volumeMounts:
- name: sync-dir
mountPath: /abc/xyz #Any Real path like (/opt/software)
volumes:
- name: sync-dir
hostPath:
path: /abc/xyz
---
apiVersion: v1
kind: Service
metadata:
name: setup
labels:
app: setup
spec:
ports:
- name: tcp-8081-8081-setup
port: 8081
targetPort: 8081
protocol: TCP
selector:
app: setup
type: LoadBalancer
externalIPs:
- 192.168.1.249 #Here comes public IP or write both
sessionAffinity: None
externalTrafficPolicy: Cluster
status:
loadBalancer: {}
And also visit this guide for more details about the volume mount as said by Arghya Sadhu