日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET Core在Azure Kubernetes Service中的部署和管理

發布時間:2023/12/4 asp.net 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET Core在Azure Kubernetes Service中的部署和管理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目標

部署:掌握將aspnetcore程序成功發布到Azure Kubernetes Service(AKS)上
管理:掌握將AKS上的aspnetcore程序擴容、更新版本

準備工作

注冊 Azure 賬戶

官網
免費帳戶

Azure 免費帳戶僅適用于新用戶,并且僅限每個客戶一個免費帳戶。

AKS文檔

AKS文檔首頁
azure中文文檔

Azure有兩種管理方式 Azure Cli 和 Azure 門戶。

進入Azure門戶(控制臺)

門戶(控制臺)

搜索AKS,選中Azure Kubernetes Service,進入AKS控制臺。

安裝 Azure Cli

安裝文檔

主要使用Cli方式管理Azure。

安裝 Docker

Docker首頁
DockerHub

進入正題

Azure 相關概念

資源組

創建資源組

az group create --name myResourceGroup --location eastasia

刪除資源組

az group delete --name myResourceGroup --yes --no-wait

容器注冊表 Azure Container Register (ACR)

使用 ACR 管理 Docker 鏡像。

創建 ACR

az acr create --resource-group boot-camp-2019 --name azurebootcamp2019 --sku Basic

登錄 ACR

az acr login --name azurebootcamp2019

服務主體 service principle

創建服務主體

az ad sp create-for-rbac --skip-assignment

記下返回信息 appId 和 password,返回格式如下

{
"appId": "d67dc2f9-d8d1-4a2c-a2ef-df15cc3710c1",
"displayName": "azure-cli-2019-04-21-11-46-32",
"name": "http://azure-cli-2019-04-21-11-46-32",
"password": "4488581b-d297-4488-ac4a-154400df8acd",
"tenant": "16cdead3-aec0-4dcb-acc4-d9c862f105d3"
}

給服務主體配置 ACR 的pull權限

查詢 ACR 的 arcId

az acr show --resource-group boot-camp-2019 --name azurebootcamp2019 --query "id" --output tsv

給服務主體分配 AcrPull 角色

# az role assignment create --assignee <appId> --scope <acrId> --role acrpull
az role assignment create --assignee d67dc2f9-d8d1-4a2c-a2ef-df15cc3710c1 --scope /subscriptions/5c029b59-2c2e-4b8b-b76b-8afde2753164/resourceGroups/boot-camp-2019/providers/Microsoft.ContainerRegistry/registries/azurebootcamp2019 --role acrpull

K8s服務集群 Azure Kubernetes Service(AKS)

創建AKS集群

# az aks create \
# --resource-group boot-camp-2019 \
# --name k8s-bootcamp2019 \
# --node-count 1 \
# --enable-addons monitoring \
# --service-principal <appId> \
# --client-secret <password> \
# --generate-ssh-keys


az aks create \
--resource-group boot-camp-2019 \
--name k8s-bootcamp2019 \
--node-count 1 \
--enable-addons monitoring \
--service-principal d67dc2f9-d8d1-4a2c-a2ef-df15cc3710c1 \
--client-secret 4488581b-d297-4488-ac4a-154400df8acd \
--generate-ssh-keys

連接AKS集群

使用 kubectl 連接AKS集群,如果沒有安裝 kubectl ,使用如下指令安裝。

az aks install-cli

將 kubectl 配置為連接到 Kubernetes 群集,如下命令將會創建集群配置以及 Kubernetes Context

az aks get-credentials --resource-group boot-camp-2019 --name k8s-bootcamp2019

驗證到群集的連接

kubectl get nodes

刪除Context

kubectl config delete-cluster k8s-bootcamp2019
kubectl config delete-context k8s-bootcamp2019

kubectl文檔

打包 Docker 鏡像

可以直接使用Docker Hub中的鏡像。也可以將鏡像上傳到ACR(推薦)。
docker 入門
dotnetcore docker 示例
Docker Hub 國內鏡像

ASP.NET Core Sample

git clone https://github.com/dotnet/dotnet-docker
cd dotnet-docker/samples/aspnetapp/
docker build -t aspnetapp .
docker run -it --rm -p 5000:80 --name aspnetcore_sample aspnetapp

標記容器映像

查詢acrLoginServer,需先登錄ACR

az acr list --resource-group boot-camp-2019 --query "[].{acrLoginServer:loginServer}" --output table

標記鏡像

# docker tag aspnetapp <acrLoginServer>/bootcamp2019web:v1
docker tag aspnetapp azurebootcamp2019.azurecr.io/bootcamp2019web:v1
docker images

推送 Docker Image 到 ACR

# docker push <acrLoginServer>/bootcamp2019web:v1
docker push azurebootcamp2019.azurecr.io/bootcamp2019web:v1

查詢 ACR 實例的映像列表

az acr repository list --name azurebootcamp2019 --output table

發布

deployment配置文件

apiVersion: apps/v1
kind: Deployment
metadata:
name: boot-camp-2019-web
spec:
replicas: 1
selector:
matchLabels:
app: boot-camp-2019-web
template:
metadata:
labels:
app: boot-camp-2019-web
spec:
containers:
- name: boot-camp-2019-web
image: azurebootcamp2019.azurecr.io/bootcamp2019web:v1
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: boot-camp-2019-web
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: boot-camp-2019-web

發布

# kubectl apply -f <配置.yaml>
kubectl apply -f ~/boot-camp-2019-web.yaml
kubectl get service boot-camp-2019-web --watch

擴容

kubectl get pods
kubectl scale --replicas=3 deployment/boot-camp-2019-web

kubectl get pods

更新

kubectl set image deployment boot-camp-2019-web boot-camp-2019-web=azurebootcamp2019.azurecr.io/bootcamp2019web:v2

dashboard

az aks browse --resource-group boot-camp-2019 --name k8s-bootcamp2019

權限問題

kubectl create clusterrolebinding kubernetes-dashboard --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard

原文地址:https://www.cnblogs.com/binking338/p/aspnetcore_on_k8s.html

.NET社區新聞,深度好文,歡迎訪問公眾號文章匯總?http://www.csharpkit.com?

總結

以上是生活随笔為你收集整理的ASP.NET Core在Azure Kubernetes Service中的部署和管理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。