If you forget a command in powershell :
Get-Command -Module *Fabric*
You need to define the user name and password in order to connect to the service fabric cluster using windows credentials with:
- Credentials Manager
- Command line:
cmdkey.exe /add:service-fabric.address /user:"domain\user_name" /pass:"password"
Connect to the service fabric cluster using windows credentials:
Connect-ServiceFabricCluster -ConnectionEndpoint 192.168.99.99:19000 -WindowsCredential
Test-ServiceFabricClusterConnection
$ServiceFabricClusterConnection = @{ ConnectionEndpoint = 'service-fabric-949735929.eu-west-1.elb.amazonaws.com:8000' ; WindowsCredential = $True }
Connect-ServiceFabricCluster $ServiceFabricClusterConnection
Get-ServiceFabricApplication
Get-ServiceFabricApplication | Test-ServiceFabricApplication
Get-ServiceFabricApplication | Get-ServiceFabricService
Get-ServiceFabricApplication | Get-ServiceFabricService | Test-ServiceFabricService
Get-ServiceFabricApplication | Get-ServiceFabricService | Get-ServiceFabricPartition
Service Fabric runs applications by default under the LOCAL_AUTHORITY user so
ASPNETCORE_ENVIRONMENT=Development
The secrets are stored at the following path
%APPDATA%\microsoft\UserSecrets\<userSecretsId>\secrets.json
Examples:
- user :
C:\Users\{user}\AppData\Roaming\Microsoft\UserSecrets\{SECRET_ID}\secrets.json
- service fabric (LOCAL_AUTHORITY) :
C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\Microsoft\UserSecrets\{SECRET_ID}\secrets.json
In order to use your own secrets in service fabric for development purpose you can make a symlink to your secrets:
mklink /D /H %WINDIR%\system32\config\systemprofile\AppData\Roaming\Microsoft\UserSecrets %APPDATA%\Microsoft\UserSecrets
- https://docs.microsoft.com/en-gb/azure/service-fabric/service-fabric-reliable-services-communication-aspnetcore
- https://msdn.microsoft.com/en-us/magazine/mt595752.aspx?f=255&MSPPError=-2147217396
- http://blogs.recneps.net/post/Custom-ASPNET-MVC-app-running-in-a-Container-on-Service-Fabric
- https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-deploy-container
- https://github.com/Microsoft/azure-docs/blob/master/articles/service-fabric/service-fabric-deploy-container.md
- https://blogs.msdn.microsoft.com/azureservicefabric/2016/04/25/orchestrating-containers-with-service-fabric/
Service Fabric are not able to redirect requests to the docker container which locates on the same box due to Windows NAT limitation. There is a workaround for it just to use placement-constraints to deploy docker images on another boxes than reverse proxy.
- Deployment Strategies
- Blue/Green Deployment
- Application Upgrade
- Octopus: Deploying a package to a Azure Service Fabric cluster
Connect-ServiceFabricCluster -ConnectionEndpoint 'idealcluster.westus.cloudapp.azure.com:19000'
Copy-ServiceFabricApplicationPackage -ApplicationPackagePath . -ImageStoreConnectionString "fabric:ImageStore" -ApplicationPackagePathInImageStore "ActorTicTacToeApplicationType"
Register-ServiceFabricApplicationType -ApplicationPathInImageStore "ActorTicTacToeApplicationType"
New-ServiceFabricApplication "fabric:/ActorTicTacToeApplication" "ActorTicTacToeApplicationType" "1.0.2"
#Remove-ServiceFabricApplication "fabric:/ActorTicTacToeApplication"
build.bat
file
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsMSBuildCmd.bat"
for /f %%f in ('dir /s/b *.sln') do MSBuild.exe -t:Clean,Restore,Build /p:Configuration=Release /p:Platform="x64" %%f
for /f %%f in ('dir /s/b *.sfproj') do MSBuild.exe -t:Package /p:Configuration=Release /p:Platform="x64" %%f
pushd %CD%
for /f %%f in ('dir /s/b pkg') do (
cd %%f\..
xcopy /I /F /V /Y PublishProfiles\*.xml pkg\Release\PublishProfiles
xcopy /I /F /V /Y ApplicationParameters\*.xml pkg\Release\ApplicationParameters
)
popd
deploy.ps1
file
<#
.SYNOPSIS
Deploys a Service Fabric application type to a cluster.
.EXAMPLE
Connect-ServiceFabricCluster -ConnectionEndpoint service-fabric-949735929.eu-west-1.elb.amazonaws.com:8000 -WindowsCredential
.\build.ps1 -UseExistingClusterConnection
#>
param (
[Switch]
$UseExistingClusterConnection = $true,
[String][ValidateSet('Release', 'Debug')]
$Configuration = 'Release',
[String]
$PublishProfileFile = "Cloud.xml",
[Hashtable]
$ApplicationParameters = @{},
[String][ValidateSet('None', 'ForceUpgrade', 'VetoUpgrade')]
$OverrideUpgradeBehavior = 'None',
[String][ValidateSet('Never', 'Always', 'SameAppTypeAndVersion')]
$OverwriteBehavior = 'Never',
[Switch]
$DeployOnly = $false,
[Switch]
$SkipPackageValidation = $false,
[Switch]
$UnregisterUnusedApplicationVersionsAfterUpgrade = $false
)
Get-ChildItem -Recurse -Directory -Filter pkg | ForEach-Object {
$DIR = $_.Parent.FullName
Write-Host "Deploying $DIR"
& "$DIR\Scripts\Deploy-FabricApplication.ps1" `
-UseExistingClusterConnection:$UseExistingClusterConnection `
-ApplicationPackagePath "$DIR\pkg\$Configuration" `
-PublishProfileFile "$DIR\pkg\$Configuration\PublishProfiles\$PublishProfileFile" `
-ApplicationParameter:$ApplicationParameters `
-OverrideUpgradeBehavior $OverrideUpgradeBehavior `
-OverwriteBehavior $OverwriteBehavior `
-DeployOnly:$DeployOnly `
-SkipPackageValidation:$SkipPackageValidation `
-UnregisterUnusedApplicationVersionsAfterUpgrade $UnregisterUnusedApplicationVersionsAfterUpgrade `
-ErrorAction Stop
}
Connect-ServiceFabricCluster -ConnectionEndpoint 'service-fabric-949735929.eu-west-1.elb.amazonaws.com:8000' -WindowsCredential
$ApplicationParameters = @{ AppSettings_ProjectKey="zxcasd" ; AppSettings_ClientId="gF47ep" ; AppSettings_ClientSecret="qwerty123" }
.\deploy.ps1 -UseExistingClusterConnection -PublishProfileFile "Cloud.xml" -ApplicationParameters $ApplicationParameters
- Describing a service fabric cluster
- How to create a Service Fabric standalone cluster with AWS EC2 instances
- Customize Service Fabric cluster settings and Fabric Upgrade policy
- Secure a standalone cluster on Windows by using Windows security
- Connect to the service fabric cluster
- https://docs.aws.amazon.com/directoryservice/latest/admin-guide/microsoftadbasestep3.html
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
New-NetFirewallRule -DisplayName "Allow inbound ICMPv4" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -RemoteAddress Any -Action Allow
New-NetFirewallRule -DisplayName "Allow inbound Service Fabric Int" -Direction Inbound -Protocol TCP -LocalPort 135,137-139,445 -RemoteAddress Any -Action Allow
New-NetFirewallRule -DisplayName "Allow inbound Serfice Fabric Ext" -Direction Inbound -Protocol TCP -LocalPort 19000-19003,19080-19081,20001-21000 -RemoteAddress Any -Action Allow
Set-Service -Name RemoteRegistry -StartUpType Automatic
Start-Service -Name RemoteRegistry
Get-Service -Name RemoteRegistry
Invoke-WebRequest "http://go.microsoft.com/fwlink/?LinkId=730690" -OutFile c:\sf.zip
#Start-BitsTransfer -Source "http://go.microsoft.com/fwlink/?LinkId=730690" -Destination c:\SF.zip
Expand-Archive c:\sf.zip c:\sf
- Make a copy of the
ClusterConfig.Windows.MultiMachine.json
example configuration file.xcopy .\ClusterConfig.Windows.MultiMachine.json .\ClusterConfig.AWS.json*
- Replace the
$.nodes.*.iPAddress
fields with the machine names - Add the following object to the
$.properties.fabricSettings
array:{ "name": "FileStoreService", "parameters": [ { "name": "AnonymousAccessEnabled", "value": "true" } ] }
- Add the users who have permissions to work with the cluster
- The last step to create a cluster is to execute the powershell script
.\CreateServiceFabricCluster.ps1 -ClusterConfigFilePath .\ClusterConfig.AWS.json -AcceptEULA
- https://docs.microsoft.com/en-gb/azure/service-fabric/service-fabric-deploy-remove-applications
- https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-controlled-chaos
.\AddNode.ps1 -NodeName 'vm3' -NodeType 'NodeType0' -NodeIpAddressOrFQDN "$Env:COMPUTERNAME" -UpgradeDomain 'UD3' -FaultDomain 'fd:/dc1/r3' -ExistingClientConnectionEndpoint '192.168.5.46:19000' -AcceptEULA
# or using Add-ServiceFabricNode directly
.\RemoveNode.ps1 -ExistingClientConnectionEndpoint 192.168.5.251:19000
# or using Remove-ServiceFabricNode directly
Get-ServiceFabricClusterConfiguration
Start-ServiceFabricClusterConfigurationUpgrade -ClusterConfigPath .\ClusterConfig.AWS.json
Restart-ServiceFabricNode -NodeName vm3 -CommandCompletionMode Verify
Update-ServiceFabricService -Stateful 'fabric:/System/ImageStoreService' -MinReplicaSetSize 3 -TargetReplicaSetSize 3 -Force
Repair-ServiceFabricPartition -All -Force
$app = Get-ServiceFabricApplication -ApplicationName "fabric:/xxx"
$table = @{}
$app.ApplicationParameters | ForEach-Object { $table.Add($_.Name, $_.Value) }
Start-ServiceFabricApplicationUpgrade -ApplicationName "fabric:/xxx" -ApplicationTypeVersion 1.0.0 -ApplicationParameter $table -HealthCheckStableDurationSec 60 -UpgradeDomainTimeoutSec 1200 -UpgradeTimeout 3000 -FailureAction Rollback -Monitored
function Add-ServiceFabricUser([bool]$isAdmin=$False, [Parameter(Mandatory=$True)]$identity) {
$configPath = ".\ClusterConfig.$((Get-Date).Ticks).json"
$config = Get-ServiceFabricClusterConfiguration | ConvertFrom-Json
$config.Properties.Security.WindowsIdentities.ClientIdentities = $config.Properties.Security.WindowsIdentities.ClientIdentities + [PsCustomObject]@{ IsAdmin = $isAdmin; Identity = $identity }
$config.ClusterConfigurationVersion = [version]$config.ClusterConfigurationVersion | foreach { (New-Object -TypeName System.Version -ArgumentList $_.Major, $_.Minor, $_.Build, ($_.Revision + 2)).ToString() }
$config | ConvertTo-Json -Depth 50 | Set-Content -Path $configPath
Start-ServiceFabricClusterConfigurationUpgrade -ClusterConfigPath $configPath
return Get-ServiceFabricClusterConfigurationUpgradeStatus
}
cd C:\ProgramData\SF
Get-ChildItem -Path . -Include *.json,*.xml -Recurse | Select-String -Pattern '[CONTENT]' -AllMatches | group path | select name