This requirement is primarily for a development environment.
As I update a docker image using which a deployment is created and exposed through Minikube, I have to delete and re-create this deployment and service. However, I'd like to maintain the same nodeport that was assigned to that particular service. I know that if left to Minikube, a random port is assigned. But can I specify the NodePort?
I create the deployment using the following Yaml file and expose the service through the expose command.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: dpl_name
spec:
template:
metadata:
labels:
app: app_name
spec:
containers:
- name: ctr_name
image: 192.168.42.22:80/imagename:latest
ports:
- containerPort: 8090
volumeMounts:
- mountPath: /var/containerdata
name: vlm
volumes:
- name: vlm
hostPath:
path: '/data/vlm'
You can expose the deployment by creating a service of type NodePort and specifying the nodePort value in that .yaml configuration:
kind: Service
apiVersion: v1
metadata:
name: app_name
labels:
app: app_name
spec:
type: NodePort
ports:
- port: 80
targetPort: 8090
nodePort: 30000 # <--
selector:
app: app_name
This will specify to always use the nodePort value: 30000