Removing units in a k8s model is a bit different. There is the ‘scale’ method, but you don’t get control over which unit is removed. Am I right @wallyworld?
For k8s, a Kubernetes deployment controller (or stateful set) is used to manage the scale out of an application. On that basis, you can specify the number of units you want, but cannot remove them individually as Juju has no control over how the cluster ultimately manages the pods.
The Juju CLI provides operations like:
Set total number of units/pods to 3 $ juju scale-application mariadb-k8s 3
Increase the number of units/pods by 2
$ juju add-unit mariadb-k8s --num-units 2
Decrease the number of units/pods by 1
$ juju remove-unit mariadb-k8s --num-units 1
juju help remove-unit mentions the k8s specific behaviour but the feedback when running the command definitely should be improved and we’ll do that.
I can see that in your case you perhaps want to delete unit 2 because it’s in error and start again. The issue is that the k8s doc is pretty clear about the fact that it can be dangerous to directly delete a statefulset pod; https://kubernetes.io/docs/tasks/run-application/force-delete-stateful-set-pod/
Also, because pod identity is stable with stateful sets, even if you were to use kubectl to delete the pod corresponding to unit 2, the unit on the Juju side would be marked as “terminated”, k8s would recreate a new pod with the same name, and the same unit on the Juju side would become active again. This is needed to allow the k8s cluster to restart stateful set pods (as needed in response to nodes going down or whatever) and have Juju units remain stable to such events.
The current answer would be to upgrade the charm to fix the logic error in the hook and allow the unit to come good again.
I think it is pretty clear that our error messages don’t really point you in the right direction. It shouldn’t tell you that a unit is an invalid application name, it should tell you that you cannot remove specific units from kubernetes applications. And ideally we would point you towards ‘--num-units’ if you supply an application name but no count. (we sort of do, but we don’t say ‘num-units’ in those words.)