6. Agenda
• Why containers?
• Building Containerized ASP.NET Core app
• Deploying Containers on Kubernetes and
Azure
• Advantages of Kubernetes
7.
8. What if we could remove
configuration complexity,
dependency conflicts and
uncertainty?
9. > docker run –p 6379:6379 redis:3.0.3
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.3 (00000000/0) 64 bit
.-`` .-```. ```/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1:M 05 Nov 10:42:24.402 # Server started, Redis version 3.0.3
1:M 05 Nov 10:42:24.402 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.
To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl
vm.overcommit_memory=1' for this to take effect.
10. > 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.
11.
12.
13.
14. Own Process Space
Own Network Interface
Own Root Directories
Sandboxed
It’s not a VM!
Container
20. Open Container Initiative
• Driven by Linux Foundation
• Docker Containers === Runtime Specification
• Docker Images === Image Specification
• CRI-O === Kubernetes Container Runtime
21. > 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.
34. > cat Dockerfile
FROM node:6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
CMD [ "npm", "start" ]
> docker build –t nodeapp .
> docker run –d –p 3000 nodeapp
35.
36. Example – ASP.NET
FROM microsoft/dotnet:1.1.1-sdk
WORKDIR /app
# copy csproj and restore as distinct layers
COPY dotnetapp.csproj /app/
RUN dotnet restore
COPY . /app/
RUN dotnet publish -c Release -o out
CMD ["dotnet", "out/dotnetapp.dll"]
37. Deploying Build Tools
REPOSITORY TAG IMAGE ID
CREATED SIZE
katacoda/dotnet-example v1 b8f8b523d3ca
6 minutes ago 894.7 MB
38. Example – ASP.NET
FROM microsoft/dotnet:1.1.1-runtime
WORKDIR /app
COPY out /app
ENTRYPOINT ["dotnet", "dotnetapp.dll"]
39. # 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/
40. 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
64. > az login
> az account set --subscription "8640e4e6-"
> az group create -n "demo-k8s" -l "westeurope"
> az ad sp create-for-rbac --role="Contributor" --
scopes="/subscriptions/8640e4e6/resourceGroups/demo-k8s"
68. > DNS_PREFIX=some-unique-value
> CLUSTER_NAME=any-acs-cluster-name
> az acs create --orchestrator-type=kubernetes
--resource-group $RESOURCE_GROUP
--name=$CLUSTER_NAME --dns-prefix=$DNS_PREFIX
--generate-ssh-keys
> az acs kubernetes install-cli
> az acs kubernetes get-credentials
--resource-group=$RESOURCE_GROUP
--name=$CLUSTER_NAME
69.
70. > ssh katacoda@52.174.195.10
or install client tools (kubectl) locally…
$ kubectl get nodes
NAME STATUS AGE VERSION
k8s-agent-4c8a65bf-0 Ready 9m v1.6.2
k8s-master-4c8a65bf-0 Ready,SchedulingDisabled 9m v1.6.2
71. $ kubectl run dotnetapp
--image katacoda/dotnet-example:v1
deployment "dotnetapp" created
72. $ kubectl run dotnetapp --image katacoda/dotnet-example:v1
deployment "dotnetapp" created
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
dotnetapp 1 1 1 1 5m
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
dotnetapp-2582115574-b59rg 1/1 Running 0 20s
82. $ kubectl get nodes
NAME STATUS AGE VERSION
k8s-agent-4c8a65bf-0 Ready 34m v1.6.2
k8s-agent-4c8a65bf-1 NotReady 15s v1.6.2
k8s-master-4c8a65bf-0 Ready,SchedulingDisabled 34m v1.6.2
wait for node to be configured…
$ kubectl get nodes
NAME STATUS AGE VERSION
k8s-agent-4c8a65bf-0 Ready 34m v1.6.2
k8s-agent-4c8a65bf-1 Ready 2m v1.6.2
k8s-master-4c8a65bf-0 Ready,SchedulingDisabled 34m v1.6.2
83. $ kubectl scale --replicas=6 deployment/dotnetapp
$ kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
dotnetapp 6 6 6 3 23m
wait for containers to be downloaded…
$ kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
dotnetapp 6 6 6 3 24m