Delete Service fabric Service via ARM template - azure-service-fabric

I have an application, that has 3 services (Service 1 to 3) and I deploy these services via ARM templates to different clusters. Service 3 now needs to be removed. Now, when I change my application manifest to just remove that service and deploy my ARM templates, Service Fabric deployment fails with the following error:
{
"ClassName": "System.Fabric.FabricException",
"Message": "Services must be explicitly deleted before removing their Service Types ......"
}
Searching on the internet, I see that the service needs to be removed using the Remove-ServiceFabricService cmdlet.
I wanted to check if that is the only option to delete services OR is there any other way using ARM templates to remove SF services or may be a way to disable the above check since the deletion is intentional.

Currently, the documentation says you have to use Powershell to remove them:
To delete an application that was deployed by using the application
resource model in Resource Manager:
Use the Get-AzResource cmdlet to get the resource ID for the
application:
Get-AzResource -Name <String> | f1
Use the Remove-AzResource cmdlet to delete the application resources:
Remove-AzResource -ResourceId <String> [-Force] [-ApiVersion <String>]

Related

Deploy app to service fabric with PowerShell

I have service fabric up and running in Azure. Also I have Visual Studio solution with two projects: Service Fabric and Web Service.
I would like to deploy the service to the service fabric in azure.
When I right-click my service fabric project and click "Publish", the service smoothly deploys to the cloud fabric. I would like to do the same with PowerShell.
It seems I need to run this script:
# Connect to the cluster using a client certificate.
Connect-ServiceFabricCluster -ConnectionEndpoint $endpoint `
-KeepAliveIntervalInSec 10 `
-X509Credential -ServerCertThumbprint $thumbprint `
-FindType FindByThumbprint -FindValue $thumbprint `
-StoreLocation CurrentUser -StoreName My
# Copy the application package to the cluster image store.
Copy-ServiceFabricApplicationPackage $packagepath -ImageStoreConnectionString fabric:ImageStore -ApplicationPackagePathInImageStore $packagename
# Register the application type.
Register-ServiceFabricApplicationType -ApplicationPathInImageStore $packagename
# Create the service instance.
$appName = <name that I see in fabric explorer under 'typeName' in azure>
New-ServiceFabricService -ApplicationName fabric:/$appName -ServiceName fabric:/$appName/MyApp -ServiceTypeName $serviceTypeName -Stateless -PartitionSchemeSingleton -InstanceCount -1
Prior to running the script I right click my fabric app and select "Package".
The very last command of my script fails with "application not found"
What can be missing?
Once you have the package build and ready, you can try the below commands in order to deploy the pkg using PowerShell Script.
If you haven't tried the below option, try this and see if it works.
There are few prerequisites that's needed in order to run the script :
You have your cluster up and running.
Cluster has all necessary certificates deployed (such as for SSL
endpoints, if any)
You have ARM template and parameters files ready.
You have the necessary permissions for deployment of new resources,
namely the Contributor role (on the level of subscription or resource
group)
You have the destination resource group created
Once you check the above, execute the following commands:
Copy-ServiceFabricApplicationPackage
Register-ServiceFabricApplicationType
New-ServiceFabricApplication
If that doesn't work for you, go through the below sites to see if it helps .
Deploy applications using PowerShell
Deploy resources with Resource Manager templates and Azure PowerShell
The problem was that I used wrong ApplicationName and ServiceName in the command New-ServiceFabricService.
In order to find out what correct values are, I ran Get-ServiceFabricApplication and Get-ServiceFabricService.
These pages were very helpful for building troubleshooting the scripts:
Deploy and remove applications using PowerShell
Service Fabric application upgrade using PowerShell

How to get meaningful alias or name for provisioned service in IBM Cloud?

I am using the CLI command bx service create to provision a new service. Some of the services support resource groups. For them, I noticed that the service itself has a long generic name and is listed under "Services". The name I chose is only associated with an alias, listed under "Cloud Foundry Services".
How can I get those services to use the name I picked?
The trick is to use another IBM Cloud CLI command. It is part of the set of commands to manage resource groups and its objects:
bx resource service-instance-create
Using the above command, the name is used for the service and there is no alias created. The service is only listed under "Services". Here is a full example:
bx resource service-instance-create ghstatsDDE dynamic-dashboard-embedded lite us-south

Get-AzureNetworkSecurityGroup not working

I try too add some Security roules in my Azure NSG via Powershell, but
Get-AzureNetworkSecurityGroup
doesn't seem to work, it alway returns nothing. I can't select a NSG by Name too
Get-AzureNetworkSecurityGroup -Name myname
Although
Find-AzureRmResource -ResourceNameContains nsg
finds my NSGs.
What do I do wrong?
Thanks
Get-AzureNetworkSecurityGroup is meant for NSG's created using the classic deployment model (Old Portal). This will yeild output only if you have classic NSG's in your subscription.
You have indicated that you get output when you use the Find-AzureRmResource commandlet. Now this is a commandlet for the resources created using the ARM deployment model in Azure. One easy way to identify the Resource Manager commandlets is to look for the letters RM in the commandlet.
Looks like you have NSG's created using Resource Manager, so try the following:
Get-AzureRmNetworkSecurityGroup -Name nsg1 -ResourceGroupName "KaushalRG"
Looks for network security group "nsg1" in resource group "KaushalRG"
More information on the deployment models in Azure can be found here: Azure Resource Manager vs. classic deployment

Azure PowerShell - Set-AzureService : ResourceNotFound: The hosted service does not exist

I was recently trying to configure reverse dns for my mail server (which is hosted on Azure). But everytime I try this command:
Set-AzureService –ServiceName “MyVMName” -Description "VM with reverse dns" –ReverseDnsFqdn “myvmname.cloudapp.net."
It can't find the resource:
(Set-AzureService : ResourceNotFound: The hosted service does not
exist.)
And when I type in Get-AzureRmResource, I have all my resources, including my VM. So I don't understand, I really hope you guys can help me, because it's almost like I can't send mail without the reverse dns record.
From what I see, your Virtual Machine is created with Azure Resource Manager, while you try to set the reverse DNS entry using the Azure Service Management. This will not work.
Here is an article describing what is the difference between Azure Resource Manager and Azure Service Management and why that matters.
And here is an article on how to set Reverse DNS for your VM using Resource Manager.
AzureService will only show ASM (classic) service:
Set-AzureService
When you type:
Get-AzureRmResource
It will display all the ARM (resource manager). Therefore this will not work because you are looking at two different things.

How to update a cloud service on Azure with a limited user account from the command line

The service I wish to upgrade is in a resource group and my user account is configured as an owner of that resource group. The user account is limited to only access the one resource group.
I can successfully update the cloud service using the new management portal by uploading a cspkg and a cscfg file.
I'm trying to automate this process using Azure Powershell.
This is what I've tried so far:
Set-AzureDeployment -Upgrade -ServiceName test-service -Configuration C:\temp\test-service.cscfg -Package "https://test-service.blob.core.windows.net/azurepowershelldeploy/test-package.cspkg" -Slot Production -Mode Auto -Label test-2015-07-28T00:33:04
ForbiddenError: The server failed to authenticate the request.
Verify that the certificate is valid and is associated with this subscription.
Having a look in fiddler, it's making a request to this endpoint, and getting back a 403 forbidden.
POST /xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/services/hostedservices/test-service/deploymentslots/Production/?comp=upgrade HTTP/1.1
I believe the ASM API's don't work properly with resource groups. Is there a method to update a cloud service using the new ARM API's?
You can deploy, update or delete all of the resources for your application in a single, coordinated operation using ARM.
You would redeploy your ARM template to an existing RG using:New-AzureResourceGroupDeployment
The New-AzureResourceGroupDeployment cmdlet adds a deployment to an existing resource group, including the resources that the deployment needs. This cmdlet is similar to the New-AzureResourceGroup cmdlet, but it works on existing resource groups, instead of new ones. To add a single resource to a resource group, use the New-AzureResource cmdlet.
A good walk through for your scenario (with a few changes) is at: Provision and deploy microservices predictably in Azure
This tutorial shows how to provision and deploy an application composed of microservices in Azure App Service as a single unit and in a predictable manner using JSON resource group templates and PowerShell scripting.
Instead of using an app service resource in the RG template, use the types of resources you'd need. Then call the above New-AzureResourceGroupDeployment cmdlet instead of New-AzureResourceGroup cmdlet.