You have good Microsoft Article on That. And it is upgrading-always-on-availability-group-replica-instances. This also applies to WIndows Server update. Quoting from the Article
When upgrading a SQL Server instance that hosts an Always On Availability Group (AG) to a new SQL Server 2019 (15.x) version, to a new SQL Server service pack or cumulative update, or when installing to a new Windows service pack or cumulative update, you can reduce downtime for the primary replica to only a single manual failover by performing a rolling upgrade.
Basically the step is
- Apply service pack or cumulative update on the secondary replica.
- If an instance hosts both primary and secondary replica. Failover such that the instance only hosts
secondary replica - Post SP/CU upgrade failover to newly patched replica.
- Now apply patch on other secondary replicas and repeat the steps 1-3 till all the replicas are patched.
Now if you read the article it has few recommendations mentioned as what to do before applying SP/CU please follow that.
- Like taking complete SQL Sever backup.
- Making sure replicas are green in Availability Group dashboard when you plan to apply CP/CU
- Apply SP/CU only when load is very very less or preferably during application downtime.
- Before applying Sp/CU manually failover and check that your AG is working fine. I understand you
cannot do this with Production Database always but yes it is best to make sure that system is good
in terms of failover before upgrading. - Please test your SP/CU on UAT before applying it on production.
Please read the document completely to get more insight.