At the moment, it is not possible to publish a layer with (referenced) data using arcpy to ArcGIS Enterprise, while maintaining the Layer configuration like PopUp Settings.
References:
https://gis.stackexchange.com/questions/361345/how-can-i-get-a-configured-pop-up-in-arcgis-pro-to-publish-to-portal
https://community.esri.com/t5/arcgis-enterprise-questions/pop-up-created-in-pro-does-not-work-when-published/td-p/363435
https://community.esri.com/t5/arcgis-pro-questions/popup-information-not-published-to-arcgis/td-p/119079
https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-configure-map-image-layer-pop-up-attributes/td-p/1026107
The "Share As" tools are not exposed as their own tools and can not be used in arcpy or in model builder, as explained here: https://community.esri.com/t5/modelbuilder-questions/quot-overwrite-web-layer-quot-tool-in-model/td-p/777741 (No, Replace Web Layer does not help, as it does not support all Layer types)
The arcpy scripts (that can be found online) at the moment only allow to create and publish sddraft/sd files and do not include the popup information. In the Upload Service Definition Stage this important information is dismissed: see https://community.esri.com/t5/arcgis-pro-questions/popup-information-not-published-to-arcgis/td-p/119079
Possible solutions:
For automated workflows, it is important to be able to share Layers the same way a ArcGIS Pro does.
(We need arcpy access to the same steps, that the Share As tools perform in the background)
If it is not possible to expose the "Share As" tools as individual Geoprocessing tools (which would be great),
please fix the Publishing Bug that avoids the missing Layer information when publishing using arcpy.
Alternatively provide a tool that can generate the Layer-Information from the CIM Layer into the JSON Format used by the item JSON in Portal. Then we could publish the service using an SD file and update the item JSON with the popup information exported from the ArcGIS Pro project, all directly from within arcpy.
Bug: https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEzOTI1Mw==