Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
k8s_basic_deployments [2020/05/02 17:02] – [Rolling-Updates] andonovj | k8s_basic_deployments [2020/05/03 12:16] (current) – andonovj | ||
---|---|---|---|
Line 153: | Line 153: | ||
What we do then ? | What we do then ? | ||
- | |||
Well, let's edit our application, | Well, let's edit our application, | ||
+ | ====Edit Software==== | ||
<Code: C#|Edit Source> | <Code: C#|Edit Source> | ||
namespace HttpServerDemo | namespace HttpServerDemo | ||
Line 166: | Line 166: | ||
using System.IO; | using System.IO; | ||
using System.Threading; | using System.Threading; | ||
- | |||
class Program | class Program | ||
{ | { | ||
Line 173: | Line 172: | ||
TcpListener tcpListener = new TcpListener(IPAddress.Any, | TcpListener tcpListener = new TcpListener(IPAddress.Any, | ||
tcpListener.Start(); | tcpListener.Start(); | ||
- | |||
while (true) | while (true) | ||
{ | { | ||
TcpClient tcpClient = await tcpListener.AcceptTcpClientAsync(); | TcpClient tcpClient = await tcpListener.AcceptTcpClientAsync(); | ||
await ProcessClientAsync(tcpClient); | await ProcessClientAsync(tcpClient); | ||
- | |||
} | } | ||
} | } | ||
Line 190: | Line 187: | ||
int bytesRead = await networkStream.ReadAsync(requestBytes, | int bytesRead = await networkStream.ReadAsync(requestBytes, | ||
string request = Encoding.UTF8.GetString(requestBytes, | string request = Encoding.UTF8.GetString(requestBytes, | ||
- | string responseText = @"< | + | string responseText = @"< |
$"< | $"< | ||
string response = " | string response = " | ||
Line 211: | Line 208: | ||
The Rebuild part you can see in the Docker section, but I will put the output here as well: | The Rebuild part you can see in the Docker section, but I will put the output here as well: | ||
- | <Code: bash|Update Software, | + | ====Dockerize, |
+ | <Code: bash|Dockerize, | ||
[root@postgresqlmaster httpserverdemo]# | [root@postgresqlmaster httpserverdemo]# | ||
total 16 | total 16 | ||
Line 219: | Line 217: | ||
dr-xr-x---. 7 root root 4096 May 2 12:39 .. | dr-xr-x---. 7 root root 4096 May 2 12:39 .. | ||
drwxr-xr-x. 2 root root 71 May 2 12:45 . | drwxr-xr-x. 2 root root 71 May 2 12:45 . | ||
- | [root@postgresqlmaster httpserverdemo]# docker build -t httpserverdemo . | + | root@k8s-master:/ |
- | Sending build context to Docker daemon | + | Sending build context to Docker daemon |
- | Step 1/10 : FROM mcr.microsoft.com/ | + | Step 1/11 : FROM mcr.microsoft.com/ |
| | ||
- | Step 2/10 : WORKDIR /app | + | Step 2/11 : WORKDIR /app |
| | ||
- | | + | |
- | Step 3/10 : COPY *.csproj ./ | + | Step 3/11 : COPY *.csproj ./ |
| | ||
- | | + | |
- | Step 4/10 : RUN dotnet restore | + | Step 4/11 : RUN dotnet restore |
| | ||
- | | + | |
- | Step 5/10 : COPY . ./ | + | Step 5/11 : COPY . ./ |
- | | + | |
- | Removing intermediate container 56e2e79130b2 | + | Step 6/11 : RUN dotnet publish -c Release -o out |
- | Step 6/10 : RUN dotnet publish -c Release -o out | + | |
- | | + | |
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core | Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core | ||
Copyright (C) Microsoft Corporation. All rights reserved. | Copyright (C) Microsoft Corporation. All rights reserved. | ||
- | Restore completed in 49.81 ms for / | + | Restore completed in 38.37 ms for / |
HttpServerDemo -> / | HttpServerDemo -> / | ||
HttpServerDemo -> /app/out/ | HttpServerDemo -> /app/out/ | ||
- | ---> | + | Removing intermediate container cdccacf739ec |
- | Removing intermediate container 8d0859d775dd | + | ---> |
- | Step 7/10 : FROM mcr.microsoft.com/ | + | Step 7/11 : FROM mcr.microsoft.com/ |
- | 2.2: Pulling from dotnet/ | + | |
- | 804555ee0376: | + | Step 8/11 : WORKDIR /app |
- | 970251047358: | + | |
- | f3d4c41a4fd1: | + | ---> e6fb8470c359 |
- | bd391c46585f: | + | Step 9/11 : COPY --from=build-env /app/out . |
- | Digest: sha256: | + | |
- | Status: Downloaded newer image for mcr.microsoft.com/ | + | Step 10/11 : RUN find -type d -name bin -prune -exec rm -rf {} \; && find -type d -name obj -prune -exec rm -rf {} \; |
- | | + | |
- | Step 8/10 : WORKDIR /app | + | Removing intermediate container |
- | | + | |
- | Removing intermediate container d77bfe0f6d8f | + | Step 11/11 : ENTRYPOINT |
- | Step 9/10 : COPY --from=build-env /app/out . | + | |
- | | + | Removing intermediate container e49283dde769 |
- | Removing intermediate container | + | |
- | Step 10/10 : ENTRYPOINT dotnet HttpServerDemo.dll | + | Successfully built 9f2f48860257 |
- | | + | |
- | | + | |
- | Removing intermediate container 99cf13dd6c77 | + | |
- | Successfully built 452b7f6a095c | + | |
- | Successfully tagged httpserverdemo: | + | |
- | [root@postgresqlmaster httpserverdemo]# | + | |
- | [root@postgresqlmaster httpserverdemo]# | + | |
- | REPOSITORY | + | |
- | httpserverdemo | + | |
- | [root@postgresqlmaster httpserverdemo]# | + | |
- | [root@postgresqlmaster httpserverdemo]# | + | |
- | The push refers to a repository [docker.io/ | + | |
- | 9411dc505491: | + | |
- | e595e200408f: | + | |
- | 579a8f1d6a12: | + | |
- | 15e45d99c926: | + | |
- | 0cf75cb98eb2: | + | |
- | 814c70fdae62: | + | |
- | v2: digest: sha256: | + | |
- | [root@postgresqlmaster httpserverdemo]# | + | |
</ | </ | ||
- | aaaaand....we are done :) We have edited our awesome software and uploaded it to docker. | + | aaaaand....we are done :) We have edited our awesome software and uploaded it to docker |
+ | Let's now update the containers in the pods :) | ||
+ | |||
+ | ====Perform the Update==== | ||
+ | For that purpose, we have to edit the YAML file with couple more values like: | ||
+ | |||
+ | * Strategy: RollingUpdate(default) | ||
+ | * maxUnavailable: | ||
+ | * maxSurge: 1 - Never have more than 1 additional. In our case, never have more than 11 pods | ||
+ | |||
+ | So, our YAML file should look as follows: | ||
+ | |||
+ | <Code: bash| Updated YAML file> | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | name: hello-deploy | ||
+ | spec: | ||
+ | replicas: 10 | ||
+ | minReadySeconds: | ||
+ | strategy: | ||
+ | type: RollingUpdate | ||
+ | rollingUpdate: | ||
+ | maxUnavailable: | ||
+ | maxSurge: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: hello-date | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: hello-date | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: hello-pod | ||
+ | image: andonovj/ | ||
+ | ports: | ||
+ | - containerPort: | ||
+ | </ | ||
+ | |||
+ | Once we have the file, you can start the process as so: | ||
+ | |||
+ | <Code: bash|Rolling Update Status> | ||
+ | ubuntu@k8s-master: | ||
+ | Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply | ||
+ | deployment.apps/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | You can see the progress of the Rolling Update as follows: | ||
+ | <Code: bash|Rolling Update Status> | ||
+ | ubuntu@k8s-master: | ||
+ | Waiting for deployment " | ||
+ | ^Cubuntu@k8s-master: | ||
+ | NAME READY | ||
+ | hello-deploy-6cd458494-6mvt7 | ||
+ | hello-deploy-6cd458494-9bl7c | ||
+ | hello-deploy-6cd458494-fvwvz | ||
+ | hello-deploy-6cd458494-grp2w | ||
+ | hello-deploy-6cd458494-ldsxq | ||
+ | hello-deploy-6cd458494-lpgdj | ||
+ | hello-deploy-6cd458494-mjsmh | ||
+ | hello-deploy-6cd458494-rd58j | ||
+ | hello-deploy-6cd458494-rrkhq | ||
+ | hello-deploy-7f44bd8b96-k92sr | ||
+ | hello-deploy-7f44bd8b96-lqmdx | ||
+ | ubuntu@k8s-master: | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | </ | ||
+ | |||
+ | We can also check the version which is currently being used: | ||
+ | |||
+ | <Code: bash|Rolling Update Status> | ||
+ | ubuntu@k8s-master: | ||
+ | NAME | ||
+ | hello-deploy | ||
+ | ubuntu@k8s-master: | ||
+ | Name: | ||
+ | Namespace: | ||
+ | CreationTimestamp: | ||
+ | Labels: | ||
+ | Annotations: | ||
+ | Selector: | ||
+ | Replicas: | ||
+ | StrategyType: | ||
+ | MinReadySeconds: | ||
+ | RollingUpdateStrategy: | ||
+ | Pod Template: | ||
+ | Labels: | ||
+ | Containers: | ||
+ | | ||
+ | Image: | ||
+ | Port: | ||
+ | Host Port: 0/TCP | ||
+ | Environment: | ||
+ | Mounts: | ||
+ | Volumes: | ||
+ | Conditions: | ||
+ | Type | ||
+ | ---- | ||
+ | Available | ||
+ | Progressing | ||
+ | OldReplicaSets: | ||
+ | NewReplicaSet: | ||
+ | Events: | ||
+ | Type Reason | ||
+ | ---- ------ | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | |||
+ | </ | ||
+ | |||
+ | =====Rolling Back===== | ||
+ | Now, before we continue, let's speak a little bit about Change History. We can check the history of all changes as follows: | ||
+ | |||
+ | <Code: bash| Check Change History> | ||
+ | ubuntu@k8s-master: | ||
+ | deployment.apps/ | ||
+ | REVISION | ||
+ | 1 < | ||
+ | 2 < | ||
+ | </ | ||
+ | |||
+ | The reason why you don't see anything in the " | ||
+ | |||
+ | <Code: bash| Rollback> | ||
+ | ubuntu@k8s-master: | ||
+ | deployment.apps/ | ||
+ | ubuntu@k8s-master: | ||
+ | </ | ||
+ | |||
+ | Of course we can monitor it with the same command as before: | ||
+ | |||
+ | <Code: bash| Rollback> | ||
+ | ubuntu@k8s-master: | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | Waiting for deployment " | ||
+ | deployment " | ||
+ | ubuntu@k8s-master: | ||
+ | Name: | ||
+ | Namespace: | ||
+ | CreationTimestamp: | ||
+ | Labels: | ||
+ | Annotations: | ||
+ | Selector: | ||
+ | Replicas: | ||
+ | StrategyType: | ||
+ | MinReadySeconds: | ||
+ | RollingUpdateStrategy: | ||
+ | Pod Template: | ||
+ | Labels: | ||
+ | Containers: | ||
+ | | ||
+ | Image: | ||
+ | Port: | ||
+ | Host Port: 0/TCP | ||
+ | Environment: | ||
+ | Mounts: | ||
+ | Volumes: | ||
+ | Conditions: | ||
+ | Type | ||
+ | ---- | ||
+ | Available | ||
+ | Progressing | ||
+ | OldReplicaSets: | ||
+ | NewReplicaSet: | ||
+ | Events: | ||
+ | Type Reason | ||
+ | ---- ------ | ||
+ | Normal | ||
+ | Normal | ||
+ | Normal | ||
+ | </ | ||
+ | |||
+ | ====Rollupdate with Record==== | ||
+ | Let's again apply the RollUpdate WITH the record this time: | ||
+ | |||
+ | <Code: bash|Rollupdate with Record> | ||
+ | ubuntu@k8s-master: | ||
+ | deployment.apps/ | ||
+ | ubuntu@k8s-master: | ||
+ | ubuntu@k8s-master: | ||
+ | deployment.apps/ | ||
+ | REVISION | ||
+ | 3 < | ||
+ | 4 | ||
+ | </ | ||
+ | Now, we can see that, the record is there and we can see the history of changes. |