there is an API endpoint to set the license api/editions/set_license but as you mentioned the database migration needs to be complete in order to set the license. you can start the migration with api/system/migrate_db and then wait within your script until api/system/status returns UP to set the license automatically
sadly sonarqube is not supported to be run within k8s so you have to treat it as a legacy application. You could set the License key with the scripted approach as i already mentioned but other methodes are currently not available.
The License IS bound to the Server ID which will change if the database URI is changed.
try to deploy sonarqube really static within your k8s cluster. we hope to have a better experience running sonarqube on k8s in the future