How to configure Kubernetes deployment to run only one replica of pod always ? We can configure replicas as 1 in the deployment file but this will not prevent someone from scaling up pods using kubectl.
You could use a mutating webhook controller.
Any pod could be limited to a specific number of replicas this way.
Probably overkill for what you are trying to achieve, but it would work.
You can't directly restrict a Deployment resource to not allow more than one replica.
But you could create a custom ValidatingAdmissionWebhook admission controller that rejects requests that try to modify the replicas
field of this Deployment.
Or you could create a Custom Resource Definition (CRD) that has a similar behaviour as a Deployment, but has the number of replicas fixed to 1.
In general, if you just want to prevent certain users from scaling a replica, you could restrict the RBAC permissions for these users to prevent them from updating Deployment objects.