You are on page 1of 52

aka.

ms/APPS40 #MSIgniteTheTour
将基础架构与 Azure
Kubernetes 服务整合

aka.ms/APPS40 #MSIgniteTheTour
相关资料

本次 Session 相关资料
aka.ms/APPS40

本次 Session 相关示例代码 You’re on your way


aka.ms/APPS40Repo
to being certified!
aka.ms/app10certification
所有 Ignite Sessions 相关资料 
aka.ms/mymsignitethetour

aka.ms/APPS40 #MSIgniteTheTour
Agenda

Tailwind Traders
应用介绍
AKS 架构 介绍 Kubernetes 及其 核心 Components

可扩展性 横向扩展您的应用

网络 & 安全 Pod identity & Calico network policies

错误管理 集群 & 应用 Issues 的处理方式

aka.ms/APPS40 #MSIgniteTheTour
应用介绍 - Tailwind
Traders

aka.ms/APPS40 #MSIgniteTheTour
Tailwind Traders 组件 

Postgres SQL Virtual Machines Container instances Blob storage

aka.ms/APPS40 #MSIgniteTheTour
管理层对我们提出要求

1 弹性

2 安全

3 灵活性

4 伸缩性

aka.ms/APPS40 #MSIgniteTheTour
为什么选择 Kubernetes?

1 提供基础设施无关的标准 API

2 可自愈性

3 可伸缩性

4 可扩展性

aka.ms/APPS40 #MSIgniteTheTour
AKS 架构概览

aka.ms/APPS40 #MSIgniteTheTour
Kubernetes 架构概览
Internet

Kubernetes
control Worker node

kubelet kube-proxy

Docker
Master node
Pods Pods

API server Containers Containers

-controller-
manager -scheduler
Worker node

kubelet kube-proxy

replication, namespace,
serviceaccounts, etc. etcd

Docker

Pods Pods

Containers Containers

aka.ms/APPS40 #MSIgniteTheTour
AKS 架构概览
Azure managed control plane

Self-managed master node(s)


App/
workload Kubernetes etcd
User definition API endpoint API server Store

Controller Cloud
Scheduler Manager Controller

Schedule pods over


private tunnel
Customer VMs

Docker Docker Docker Docker Docker

Pods Pods Pods Pods Pods

aka.ms/APPS40 #MSIgniteTheTour
AKS 架构  - 网络部分

App Gateway
Kubernetes cluster: Azure VNET

Internal
Load Balancer
External
DNS

Ingress
Control plane
Controller

Worker node Worker node

kubelet Pods Pods kubelet


Containers Containers

Namespace

aka.ms/APPS40 #MSIgniteTheTour
AKS 架构  - 虚拟节点
Node Node
Pods Pods

Azure Container
Kubernetes control plane Instances (ACI)
Pods
Serverless Kubernetes 
No infrastructure to manage 
Virtual Starts in seconds
node

aka.ms/APPS40 #MSIgniteTheTour
AKS 架构  - 可用性区域
Region*

AKS AZs

Region*

AKS AZs

Region*

AKS AZs

aka.ms/APPS40 #MSIgniteTheTour
az commands

创建一个资源组
az group create \
-l <Azure region> \
此资源组包含所有用于实 -n myResGroup
验所创建的资源

aka.ms/APPS40 #MSIgniteTheTour
az commands

创建虚拟网络
az network vnet create \
--resource-group myResGroup \
--name myVnet \
同时也创建了子网,供后
续 AKS 集群使用 --address-prefixes 10.0.0.0/8 \
--subnet-name myVnetSub \
--subnet-prefix 10.240.0.0/16

aka.ms/APPS40 #MSIgniteTheTour
az commands

创建子网 az network vnet subnet create \


--resource-group myResGroup \
--vnet-name myVnet \
为虚拟节点单独创建一个 --name VNSubnet \
子网 --address-prefix 10.241.0.0/16

aka.ms/APPS40 #MSIgniteTheTour
az commands

创建 service principal
az ad sp create-for-rbac \ 
--name mySPk8s \ 
可以通过 Service
Principal 创建其他资源
–-role  Contributor 

aka.ms/APPS40 #MSIgniteTheTour
az commands

创建一个基础的 AKS 集群
az aks create \
--resource-group myResGroup \
--name myAKSCluster \
基础的 AKS 集群 --node-count 3 \
--generate-ssh-keys 

aka.ms/APPS40 #MSIgniteTheTour
az commands

创建一个标准的 AKS 集 az aks create \


群 --resource-group myResGroup \
--name myAKSCluster \
所有必备的参数选项 --node-count 3 \
--service-principal <appId> \
--client-secret <password> \
--generate-ssh-keys \
--network-plugin azure \
--dns-service-ip $KUBE_DNS_IP \
--docker-bridge-address 172.17.0.1/16 \
--vnet-subnet-id <vnet id> \
--load-balancer-sku standard \
--enable-vmss \
--node-zones 1 2 3 \
--network-policy calico
aka.ms/APPS40 #MSIgniteTheTour
az commands

添加虚拟节点
az aks enable-addons \
--resource-group myResGroup \
--name myAKSCluster \
添加 虚拟节点的 插件
--addons virtual-node \
--subnet-name VNsubnet

aka.ms/APPS40 #MSIgniteTheTour
通过开启虚拟节点、 CNI 网络
模型、可用性区域,您的集群完
全可以满足企业需求

aka.ms/APPS40 #MSIgniteTheTour
可伸缩性

aka.ms/APPS40 #MSIgniteTheTour
管理层对于功能性的需求

管理层要求我们提供新服务 . 服务必须满足:
• 根据历史数据,为客户提供个性化推荐
• 服务必须是可自动部署
• 必须提供标准的 API 接口文档,实现与其他现有服务集成

aka.ms/APPS40 #MSIgniteTheTour
应对新需求的方案设计

New consumer – customer data

aka.ms/APPS40 #MSIgniteTheTour
可伸缩性技术实现
Cluster Autoscaler

aka.ms/APPS40 #MSIgniteTheTour
可伸缩性技术实现
Horizontal Pod Autoscaler (HPA)

aka.ms/APPS40 #MSIgniteTheTour
基于 Virtual Kubelet 实现的虚拟节点

aka.ms/APPS40 #MSIgniteTheTour
虚拟节点

Linux 容器

Windows 容器
Tip

GPU 在虚拟节点背后, Helm &


ACI 一起完成了实际的工作

aka.ms/APPS40 #MSIgniteTheTour
Example.yaml

如何将你的 Pod 运行在 nodeSelector: 


beta.kubernetes.io/os: linux
虚拟节点上         kubernetes.io/role: agent
当希望将你的 Pod 运行在虚拟         type: virtual-kubelet
节点上,需要额外设置 Node       tolerations:
Selector       - key: virtual-
kubelet.io/provider
        operator: Equal
        value: azure
        effect: NoSchedule

aka.ms/APPS40 #MSIgniteTheTour
示例 :通过虚拟节点实现
弹性伸缩

aka.ms/APPS40 #MSIgniteTheTour
网络 & 安全

aka.ms/APPS40 #MSIgniteTheTour
AKS 安全实践

aka.ms/APPS40 #MSIgniteTheTour
介绍 Pod Identity

• 允许 Pod 安全的访问其他 Azure 服务

• 与 AzureAD 以及 Microsoft service identities 集成

• 灵活的支配访问权限,可随时从 Pods 中移除对于 Azure


其他服务的访问权限

aka.ms/APPS40 #MSIgniteTheTour
介绍 Pod Identity

Node Management Identity (NMI) server ,以 DaemonSet 的形式


运行在 AKS 集群中 . NMI 用于监听从 Pod 到 Azure 服务的请求

Managed Identity Controller (MIC) 是一个有权限查询 API Servers


的 Pod ,能够查看 Azure Identity 与 Pod 的对应关系

aka.ms/APPS40 #MSIgniteTheTour
Pod Identity

aka.ms/APPS40 #MSIgniteTheTour
AKS 中 Network Policy  选项

Azure 提供两种实现 Network Policy 的方式 . 当你创建集群时,选择一种支持


的 Network Policy 选项,在后期的集群运行中没有办法修改 .

aka.ms/APPS40 #MSIgniteTheTour
AKS 中 Network Policy  选项

Network policy 只有在 Azure CNI (高级网络)模式下支持 . 支持的两个选择分别是:

Azure Network Policies – Azure CNI 在 工作节点虚机中设置一个网桥 . 过滤规则将应用在所有通


过网桥的包中

Calico Network Policies – Azure CNI 设置本地 Kernel 的路由表 . 规则将被应用在 Pod 的 Nic 上

aka.ms/APPS40 #MSIgniteTheTour
Azure Network Policy

aka.ms/APPS40 #MSIgniteTheTour
Calico Network Policy

aka.ms/APPS40 #MSIgniteTheTour
示例 : Network policies

aka.ms/APPS40 #MSIgniteTheTour
管理失败

aka.ms/APPS40 #MSIgniteTheTour
Availability Zones
Region*

AKS AZs

Region*

AKS AZs

Region*

AKS AZs

aka.ms/APPS40 #MSIgniteTheTour
可用区

1 数据中心故障的恢复能力

2 节点跨区域中的 3 个数据中心拆分

3 向我们提供容错域来规划我们的部署。

aka.ms/APPS40 #MSIgniteTheTour
Availability
zones  目前正 更多更新信息请参考 :
在 Public aka.ms/AKSavailability
Preview

aka.ms/APPS40 #MSIgniteTheTour
管理应用程序的失败 Handling Application Failure

1 结合 deployments & replication, 将 replica 的数目尽量


与 Zones 的数据相同

2 使用 Ingress ControllerUse an ingress controller that is


highly available

3 了解磁盘挂载到 Pod 的机制

aka.ms/APPS40 #MSIgniteTheTour
Example.yaml

Example deployment
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: webapp-deployment
spec:
处理失败   selector:
    matchLabels:
      app: webapp
  replicas: 3
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        image: scottyc/webapp:latest
        ports:
        - containerPort: 3000
          hostPort: 3000

aka.ms/APPS40 #MSIgniteTheTour
示例 : 可用性区

aka.ms/APPS40 #MSIgniteTheTour
/MS Learn 提示
完整的学习平台,提供互动性学
习资源,环境,练习以及相对应
的培训视频,帮助云端工程师更
好的使用 Azure 云服务
aka.ms/APPS40MSLearnCollection

aka.ms/APPS40 #MSIgniteTheTour
/Microsoft 认证提醒
• Microsoft 认证 :
Azure Developer Associate
aka.ms/AzureDevCert

• Microsoft 认证 :
Azure DevOps Engineer Expert
aka.ms/DevOpsEngineerCert Get hired, stay ahead, and receive the
recognition you deserve

aka.ms/APPS40 #MSIgniteTheTour
相关资料

本次 Session 相关资料
aka.ms/APPS40

You’re on your way


本次 Session 相关示例代码 Github 地址
aka.ms/APPS40Repo
to being certified!
aka.ms/app10certification
所有 Sessions 的相关资料 
aka.ms/mymsignitethetour

aka.ms/APPS40 #MSIgniteTheTour
Invent with purpose.

You might also like