Tuesday, July 06, 2021

Running Datree on Window using Ubuntu docker Images

 1- Install docker desktop – 3-3-2-128

2- Add K8 env in it.

3- Pull Ubuntu images using below command

docker pull ubuntu

4- Now run the ubuntu image by mounting it to our folder where we keep all teh yaml files that need to be validated by DaTree.

1
2
C:\Users\Siddhartha>docker run -d -v C:\\DaTree\\yaml:/var/log/kubernetesyamlfiles -it ubuntu
048d1bfb3a3d7c76d1eccfb8ac75a4b2f09c7b5c49b51c8d868fc7ae18d66ae8

5- Now lets check our directory is properly mount using belwo command

1
2
3
4
C:\Users\Siddhartha>docker exec -ti 048d1bfb3a3d /bin/bash
root@048d1bfb3a3d:/# cd /var/log
root@048d1bfb3a3d:/var/log# ls
alternatives.log  apt  bootstrap.log  btmp  dpkg.log  faillog  kubernetesyamlfiles  lastlog  wtmp

check we have all the files in the folders kubernetesyamlfiles which is kept in our windows machine

1
2
3
root@048d1bfb3a3d:/var/log/kubernetesyamlfiles# ls
all-in-one-with-version.yaml  destination_ruleV1.yaml  gatewayV1.yaml                   springboot-docker-consumerV1.yaml  springboot-docker-producerV1.yaml  virtual-service.yaml
all-in-one.yaml               gateway.yaml             springboot-docker-consumer.yaml  springboot-docker-producer.yaml    springboot-docker-producerV2.yaml  virtual-serviceV1.yaml

6- Execute following command to install curl in it.

Update your Ubuntu box, run: apt update && apt upgrade
Next, install cURL, execute: apt install curl
Verify install of curl on Ubuntu by running: curl –version

7- Now Install Datree using below command

But before installtion you need to install two more packages

1- sudo as the script for DaTree us it internally use below command to install sudo.
apt-get install sudo
2- unzip as the script for DaTree us it internally use below command to install unzip.
sudo apt-get install unzip

Now install the DaTree using this command

curl https://get.datree.io | /bin/bash

1
2
3
4
5
6
7
8
root@048d1bfb3a3d:/var/log/kubernetesyamlfiles# curl https://get.datree.io | /bin/bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1073  100  1073    0     0   2530      0 --:--:-- --:--:-- --:--:--  2524
Installing Datree...
 
[V] Downloaded Datree
[V] Finished Installation

Now check if we had datree install properly using this command

datree test ~/.datree/k8s-demo.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Usage: $ datree test ~/.datree/k8s-demo.yaml
 
root@048d1bfb3a3d:/var/log/kubernetesyamlfiles# datree test ~/.datree/k8s-demo.yaml
>>  File: ../../../root/.datree/k8s-demo.yaml
 
[V] YAML validation
[V] Kubernetes schema validation
 
[X] Policy check
 
<img draggable="false" role="img" class="emoji" alt="❌" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/274c.svg">  Ensure each container image has a pinned (tag) version  [1 occurrences]
<img draggable="false" role="img" class="emoji" alt="💡" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f4a1.svg">  Incorrect value for key `image` - specify an image version to avoid unpleasant "version surprises" in the future
 
<img draggable="false" role="img" class="emoji" alt="❌" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/274c.svg">  Ensure each container has a configured memory limit  [1 occurrences]
<img draggable="false" role="img" class="emoji" alt="💡" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f4a1.svg">  Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization
 
<img draggable="false" role="img" class="emoji" alt="❌" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/274c.svg">  Ensure each container has a configured liveness probe  [1 occurrences]
<img draggable="false" role="img" class="emoji" alt="💡" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f4a1.svg">  Missing property object `livenessProbe` - add a properly configured livenessProbe to catch possible deadlocks
 
<img draggable="false" role="img" class="emoji" alt="❌" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/274c.svg">  Ensure workload has valid label values  [1 occurrences]
<img draggable="false" role="img" class="emoji" alt="💡" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f4a1.svg">  Incorrect value for key(s) under `labels` - the vales syntax is not valid so the Kubernetes engine will not accept it
 
 
(Summary)
 
- Passing YAML validation: 1/1
 
- Passing Kubernetes (1.18.0) schema validation: 1/1
 
- Passing policy check: 0/1
 
+-----------------------------------+----------------------------------------------------------+
| Enabled rules in policy “default” | 21                                                       |
| Configs tested against policy     | 1                                                        |
| Total rules evaluated             | 21                                                       |
| Total rules failed                | 4                                                        |
| Total rules passed                | 17                                                       |
| See all rules in policy           | https://app.datree.io/login?cliId=ksRckFcFeCzCpddprBYwnC |
+-----------------------------------+----------------------------------------------------------+
root@048d1bfb3a3d:/var/log/kubernetesyamlfiles#

This indicate that datree is installed properly.

Now lets run our Datree for one of our own made yaml files using below command

datree test /var/log/kubernetesyamlfiles/all-in-one-with-version.yaml

You will see daTree has done the validation with below concern

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
root@048d1bfb3a3d:/var/log/kubernetesyamlfiles# datree test /var/log/kubernetesyamlfiles/all-in-one-with-version.yaml
>>  File: /var/log/kubernetesyamlfiles/all-in-one-with-version.yaml
 
[V] YAML validation
[X] Kubernetes schema validation
 
<img draggable="false" role="img" class="emoji" alt="❌" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/274c.svg">  k8s schema validation error: could not find schema for Gateway
You can skip files with missing schemas instead of failing by using the `--ignore-missing-schemas` flag
 
<img draggable="false" role="img" class="emoji" alt="❌" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/274c.svg">  k8s schema validation error: could not find schema for VirtualService
You can skip files with missing schemas instead of failing by using the `--ignore-missing-schemas` flag
 
 
[?] Policy check didn’t run for this file
 
 
(Summary)
 
- Passing YAML validation: 1/1
 
- Passing Kubernetes (1.18.0) schema validation: 0/1
 
- Passing policy check: 0/1
 
+-----------------------------------+----------------------------------------------------------+
| Enabled rules in policy “default” | 21                                                       |
| Configs tested against policy     | 0                                                        |
| Total rules evaluated             | 0                                                        |
| Total rules failed                | 0                                                        |
| Total rules passed                | 0                                                        |
| See all rules in policy           | https://app.datree.io/login?cliId=ksRckFcFeCzCpddprBYwnC |
+-----------------------------------+----------------------------------------------------------+
root@048d1bfb3a3d:/var/log/kubernetesyamlfiles#

In addition DaTree also provide us the ui using this url that is shown in above table
https://app.datree.io/login?cliId=ksRckFcFeCzCpddprBYwnC

Openm url in browser and signin using github

From this url we can disable and enable certain rule that is not going to be applied to our validation.

In addition we can also change the message we look on to the prompt as show below

And now we will get the new message that is changed by us.

Anohter important use of this tool is that it give you details level information of that message and issues by clicking on i icon as shown below

In addition it will also gave you suggestion how to remove that issues

Also we can observe the history i.e. how many times we had run the datree test command and its respective output

To make sure that which version of Kubernetes we need to use that can be set from the setting option as shown below.

Best part is it also support Helm also.

No comments: