Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Deploying windows containers with kubernetes

265 views

Published on

Delivered at NDC London 2018

Visit https://Katacoda.com for more information

Published in: Technology
  • Login to see the comments

Deploying windows containers with kubernetes

  1. 1. Deploying Windows Containers with Kubernetes @Ben_Hall Ben@BenHall.me.uk Katacoda.com
  2. 2. Deploying Windows Containers with Kubernetes @Ben_Hall Ben@BenHall.me.uk Katacoda.com
  3. 3. WHOAMI?
  4. 4. Learn via Interactive Browser-Based Labs Katacoda.com
  5. 5. Agenda • Building Windows Containers • Deploying Containers on Kubernetes • Operating Kubernetes
  6. 6. > docker run -e 'ACCEPT_EULA=Y’ -e 'SA_PASSWORD=yourStrong133tPassword' -p 1433:1433 microsoft/mssql-server-linux This is an evaluation version. There are [154] days left in the evaluation period. 2017-06-09 22:16:14.27 Server Setup step is copying system data file 'C:templatedatamaster.mdf' to '/var/opt/mssql/data/master.mdf'. 2017-06-09 22:16:14.36 Server Setup step is copying system data file 'C:templatedatamastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'. 2017-06-09 22:16:14.37 Server Setup step is copying system data file 'C:templatedatamodel.mdf' to '/var/opt/mssql/data/model.mdf'. 2017-06-09 22:16:14.40 Server Setup step is copying system data file 'C:templatedatamodellog.ldf' to '/var/opt/mssql/data/modellog.ldf'. 2017-06-09 22:16:14.42 Server Setup step is copying system data file 'C:templatedatamsdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'. 2017-06-09 22:16:14.45 Server Setup step is copying system data file 'C:templatedatamsdblog.ldf' to '/var/opt/mssql/data/msdblog.ldf'. 2017-06-09 22:16:14.57 Server Microsoft SQL Server 2017 (CTP2.1) - 14.0.600.250 (X64) May 10 2017 12:21:23 Copyright (C) 2017 Microsoft Corporation. All rights reserved. Developer Edition (64-bit) on Linux (Ubuntu 16.04.2 LTS) 2017-06-09 22:16:14.58 Server UTC adjustment: 0:00 2017-06-09 22:16:14.58 Server (c) Microsoft Corporation. 2017-06-09 22:16:14.58 Server All rights reserved. 2017-06-09 22:16:14.58 Server Server process ID is 4116.
  7. 7. > docker run -it microsoft/azure-cli bash d5f51519a9b1:/# azure info: _ _____ _ ___ ___ info: /_ |_ / | | | _ __| info: _ ___/ _ __/ /| |_| | / _|___ _ _ info: (___ /_/ _/___|___/|_|____| _____) info: (_______ _ _) _ ______ _)_ _ info: (______________ _ ) (___ _ _) info: info: Microsoft Azure: Microsoft's Cloud Platform info: info: Tool version 0.10.11
  8. 8. Building Containerised ASP.NET Core app
  9. 9. > cat Program.cs namespace dotnetapp { public class Program { public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory( )) .UseUrls("http://0.0.0.0:5000") .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } } } > cat Startup.cs namespace dotnetapp { public class Startup { public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); app.Run(async (context) => { await context.Response.WriteAsync("Request processed by " + System.Environment.MachineName); }); } } }
  10. 10. $ cat Dockerfile FROM microsoft/dotnet:1.1.1-sdk
  11. 11. $ cat Dockerfile FROM microsoft/dotnet:1.1.1-sdk RUN mkdir /app WORKDIR /app COPY dotnetapp.csproj /app/ RUN dotnet restore COPY . /app RUN dotnet publish -c Release -o out EXPOSE 5000/tcp CMD ["dotnet", "out/dotnetapp.dll"]
  12. 12. $ docker build -t katacoda/dotnet-example:v1 . Sending build context to Docker daemon 137.7 kB Step 1/11 : FROM microsoft/dotnet:1.1.1-sdk Step 2/11 : RUN mkdir /build Step 3/11 : WORKDIR /build Step 4/11 : COPY dotnetapp.csproj . Step 5/11 : RUN dotnet restore Step 6/11 : COPY . . Step 7/11 : RUN dotnet publish -c Release -o out ---> Running in fcde25425eee Microsoft (R) Build Engine version 15.1.548.43366 Copyright (C) Microsoft Corporation. All rights reserved. dotnetapp -> /build/bin/Release/netcoreapp1.1/dotnetapp.dll Step 8/11 : FROM microsoft/dotnet:1.1.1-runtime Step 9/11 : WORKDIR /app Step 10/11 : CMD dotnet dotnetapp.dll Step 11/11 : COPY --from=0 /build/out /app/ Successfully built 1dbec44d4150 Successfully tagged katacoda/dotnet-example:v1.1
  13. 13. $ docker run -d -t -p 5000:5000 --name app katacoda/dotnet-example:v1 $ curl dockerhost:5000 Request processed by zb8gh24wva
  14. 14. # First Stage FROM microsoft/dotnet:1.1.1-sdk WORKDIR /app COPY dotnetapp.csproj /app/ RUN dotnet restore COPY . /app/ RUN dotnet publish -c Release -o out # Second Stage FROM microsoft/dotnet:1.1.1-runtime WORKDIR /app CMD ["dotnet", "dotnetapp.dll”] COPY --from=build out /app/
  15. 15. Optimised Image REPOSITORY TAG IMAGE ID CREATED SIZE katacoda/dotnet-example v1 d69cf725c406 5 seconds ago 266.3 MB katacoda/dotnet-example v1 b8f8b523d3ca 6 minutes ago 894.7 MB
  16. 16. http://windows-wallpapers.net/wp-content/uploads/images/1c/windows-98.png
  17. 17. Windows Server Core Windows Nano Windows Containers Windows Hyper-V Containers
  18. 18. Windows Containers Windows Kernel Windows Server 2016 SQL Server MSMQ IIS / ASP.NET Docker Engine
  19. 19. Windows Hyper-V Containers Windows Kernel Windows Server 2016 SQL Server MSMQ IIS / ASP.NET Windows Kernel Windows Utility VM Hyper-V Docker Engine
  20. 20. Windows Server Core • Nearly Win32 Compatible • Same behaviour of Windows • Install all of the same tooling
  21. 21. Windows Nano • Stripped down • Smallest footprint • 1/20th the size of Windows Server Core • Only essential components – Hyper-V, Clustering, Networking, Storage, .Net, Core CLR
  22. 22. Windows Server Core => Ubuntu Linux Windows Nano => Alpine Linux Windows Server Core => Legacy Apps? Windows Nano => Modern Apps?
  23. 23. What does this mean for us?
  24. 24. Dockerfile
  25. 25. > type Dockerfile FROM microsoft/windowsservercore:10.0.14393.693 RUN powershell.exe Install-WindowsFeature web-server > docker build –t iis .
  26. 26. > type Dockerfile FROM microsoft/iis:windowsservercore-10.0.14393.693 SHELL ["powershell", "-command“]
  27. 27. > type Dockerfile FROM microsoft/iis:windowsservercore-10.0.14393.693 SHELL ["powershell", "-command"] RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install- WindowsFeature Web-Asp-Net45
  28. 28. > type Dockerfile FROM microsoft/iis:windowsservercore-10.0.14393.693 SHELL ["powershell", "-command"] RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install- WindowsFeature Web-Asp-Net45 RUN Remove-Website -Name 'Default Web Site'; mkdir c:NerdDinner; New-Website -Name 'nerd-dinner' -Port 80 -PhysicalPath 'c:NerdDinner' -ApplicationPool '.NET v4.5‘
  29. 29. > type Dockerfile FROM microsoft/iis:windowsservercore-10.0.14393.693 SHELL ["powershell", "-command"] RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install- WindowsFeature Web-Asp-Net45 RUN Remove-Website -Name 'Default Web Site'; mkdir c:NerdDinner; New-Website -Name 'nerd-dinner' -Port 80 -PhysicalPath 'c:NerdDinner' -ApplicationPool '.NET v4.5‘ EXPOSE 80
  30. 30. > type Dockerfile FROM microsoft/iis:windowsservercore-10.0.14393.693 SHELL ["powershell", "-command"] RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install- WindowsFeature Web-Asp-Net45 RUN Remove-Website -Name 'Default Web Site'; mkdir c:NerdDinner; New-Website -Name 'nerd-dinner' -Port 80 -PhysicalPath 'c:NerdDinner' -ApplicationPool '.NET v4.5‘ EXPOSE 80 COPY NerdDinner c:NerdDinner
  31. 31. PS C:> docker build –t nerddinner .
  32. 32. PS C:> docker run -d -p 80:80 nerddinner
  33. 33. Container Orchestration
  34. 34. Kubernetes is an open- source system for automating deployment, scaling, and management of containerized applications.
  35. 35. http://queue.acm.org/detail.cfm?id=2898444
  36. 36. Kubernetes
  37. 37. Automatic binpacking Self-healing Horizontal scaling Service discovery and load balancing Automated rollouts Secret and configuration management Batch execution Role based access control Auditing API and Extension Hooks
  38. 38. http://www.ofbizian.com/2017/05/bet-on-cloud-native-ecosystem.html
  39. 39. Services Define Communication • NodePort – Hardcoded Port • ClusterIP – Cluster Assigned IP • LoadBalancer – Public IP Assigned by Cloud
  40. 40. https://www.slideshare.net/weaveworks/orch estrating-microservices-with-kubernetes
  41. 41. Infrastructure as Code apiVersion: extensions/v1beta1 kind: Deployment metadata: name: frontend-web spec: replicas: 1 template: metadata: labels: app: frontend spec: containers: - name: http-server image: katacoda/docker-http-server:latest ports: - containerPort: 80
  42. 42. Infrastructure as Code apiVersion: v1 kind: Service metadata: name: frontend-svc labels: app: frontend spec: type: NodePort ports: - port: 80 nodePort: 30080 selector: app: frontend
  43. 43. apiVersion: v1 kind: Deployment metadata: labels: name: nerddinner name: nerddinner namespace: default spec: containers: - image: benhall/nerddinner:v2.0 imagePullPolicy: Always name: nerddinner ports: - containerPort: 80 nodeSelector: beta.kubernetes.io/os: windows
  44. 44. Creating Kubernetes Cluster
  45. 45. https://twitter.com/kubernetesonarm
  46. 46. Master === Linux Only Nodes === Linux, Windows, Arm
  47. 47. Linux Containers on Windows
  48. 48. Kubeadm master$ kubeadm init linuxnode01$ kubeadm join --discovery-token abcdef.1234567890abcdef 1.2.3.4:6443 windowsnode01$ .kubeadm.exe join --discovery-token abcdef.1234567890abcdef 1.2.3.4:6443
  49. 49. kubectl master$ kubectl get nodes NAME STATUS AGE VERSION master Ready 9m v1.9.0 linuxnode01 Ready 9m v1.9.0 windowsnode01 Ready 9m v1.9.0
  50. 50. Creating AKS Service
  51. 51. $ kubectl expose deployments dotnetapp --port=80 --target-port=5000 --type=LoadBalancer service "dotnetapp" exposed $ kubectl get svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE dotnetapp 10.0.47.252 <pending> 80:31078/TCP 8s kubernetes 10.0.0.1 <none> 443/TCP 15m
  52. 52. $ kubectl expose deployments dotnetapp --port=80 --target-port=5000 --type=LoadBalancer service "dotnetapp" exposed $ kubectl get svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE dotnetapp 10.0.47.252 <pending> 80:31078/TCP 8s kubernetes 10.0.0.1 <none> 443/TCP 15m wait for Kubernetes to configure Azure LB $ kubectl get svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE dotnetapp 10.0.47.252 40.118.100.56 80:31078/TCP 5m curl 40.118.100.56
  53. 53. > curl 40.118.100.56 Request processed by dotnetapp-2582115574-b59rg > curl 40.118.100.56 Request processed by dotnetapp-2582115574-b59rg > curl 40.118.100.56 Request processed by dotnetapp-2582115574-b59rg > curl 40.118.100.56 Request processed by dotnetapp-2582115574-b59rg
  54. 54. $ kubectl scale --replicas=3 deployment/dotnetapp deployment "dotnetapp" scaled $ kubectl get deployments NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE dotnetapp 3 3 3 3 6m $ kubectl get pods NAME READY STATUS RESTARTS AGE dotnetapp-2582115574-0l028 1/1 Running 0 1m dotnetapp-2582115574-b59rg 1/1 Running 0 7m dotnetapp-2582115574-hdbc6 1/1 Running 0 1m
  55. 55. > curl 40.118.100.56 Request processed by dotnetapp-2582115574-0l028 > curl 40.118.100.56 Request processed by dotnetapp-2582115574-b59rg > curl 40.118.100.56 Request processed by dotnetapp-2582115574-hdbc6 > curl 40.118.100.56 Request processed by dotnetapp-2582115574-b59rg
  56. 56. Deploy new versions?
  57. 57. $ kubectl set image deployment/dotnetapp=katacoda/dotnet-example:v1.1 > curl 40.118.100.56 [v1.1] Request processed by dotnetapp-2582115574-0l028 > curl 40.118.100.56 Request processed by dotnetapp-2582115574-b59rg > curl 40.118.100.56 Request processed by dotnetapp-2582115574-hdbc6 > curl 40.118.100.56 [v1.1] Request processed by dotnetapp-2582115574-b59rg $ kubectl apply –f mydeployment.yaml
  58. 58. What about Private Registries?
  59. 59. > kubectl create secret docker-registry myregistrykey --docker-server=katacodademoreg1.azurecr.io --docker-username=katacodademoreg1 --docker-password=<REMOVE> --docker-email ben@benhall.me.uk secret "myregistrykey" created.
  60. 60. apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: run: dotnetapp spec: replicas: 6 strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 1 type: RollingUpdate template: spec: containers: - image: katacodademoreg1.azurecr.io/katacoda/dotnet-example:v1.1 imagePullSecrets: - name: myregistrykey metadata: labels: run: dotnetapp
  61. 61. Storage
  62. 62. > cat sqlserver.yaml apiVersion: v1 kind: Secret metadata: name: azure-secret type: Opaque data: azurestorageaccountname: <name> azurestorageaccountkey: <key> --- apiVersion: v1 kind: Pod metadata: labels: name: mssql role: master name: mssql spec: containers: - env: - name: ACCEPT_EULA value: "Y" - name: SA_PASSWORD value: yourStrong133tPassword image: microsoft/mssql-server-linux volumeMounts: - mountPath: /var/opt/mssql/data name: azure volumes: - azureFile: readOnly: false secretName: azure-secret shareName: k8stest name: azure
  63. 63. apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: serviceName: "nginx" replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: k8s.gcr.io/nginx-slim:0.8 ports: - containerPort: 80 name: web volumeMounts: - name: www mountPath: /usr/share/nginx/html volumeClaimTemplates: - metadata: name: www spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 1Gi
  64. 64. Kubernetes Operators • An Operator represents human operational knowledge in software to reliably manage an application. • https://coreos.com/operators/
  65. 65. Operators apiVersion: extensions/v1beta1 kind: Deployment metadata: name: etcd-operator spec: replicas: 1 template: metadata: labels: name: etcd-operator spec: containers: - name: etcd-operator image: quay.io/coreos/etcd-operator:v0.8.1 command: - etcd-operator env: - name: MY_POD_NAMESPACE valueFrom: https://raw.githubusercontent.com/coreos/etcd-operator/master/example/deployment.yaml
  66. 66. Operators apiVersion: "etcd.database.coreos.com/v1beta2" kind: "EtcdCluster" metadata: name: "example-etcd-cluster" spec: size: 3 version: "3.2.13" https://github.com/coreos/etcd-operator/blob/master/example/example-etcd-cluster.yaml
  67. 67. Is it still up? Monitoring with Prometheus and Kubernetes
  68. 68. apiVersion: extensions/v1beta1 kind: DaemonSet metadata: name: node-exporter spec: template: metadata: labels: app: node-exporter name: node-exporter spec: containers: - image: prom/node-exporter name: node-exporter ports: - containerPort: 9100 hostPort: 9100 name: scrape DaemonSet? When new nodes are deployed, automatically schedule workload
  69. 69. What should we monitor?
  70. 70. apiVersion: v1 kind: Service metadata: annotations: prometheus.io/scrape: 'true' labels: app: node-exporter name: node-exporter name: node-exporter spec: clusterIP: None ports: - name: scrape port: 9100 protocol: TCP selector: app: node-exporter type: ClusterIP
  71. 71. The Future?
  72. 72. SQL Server as a Container
  73. 73. Visual Studio as a Container?
  74. 74. Everything as a Container
  75. 75. Deploy Anywhere
  76. 76. www.katacoda.com
  77. 77. Online Kubernetes Training for Companies at Katacoda.com @Ben_Hall Ben@BenHall.me.uk Blog.BenHall.me.uk www.Katacoda.com

×