· 6 years ago · Dec 06, 2019, 01:00 PM
1# kubernetes-team02
2
3
4## Wymagania wstępne
5- stan repozytorium z laboratorium dotyczącym Dockera
6- minikube
7 [minikube installation](https://minikube.sigs.k8s.io/docs/start/)
8- docker
9- kubectl
10
11## Run
12
131. minicube delete (ewentualnie) & start z odpowiednią ilością CPUs i pamięci
14```bash
15$ minikube delete
16? Deleting "minikube" in virtualbox ...
17? The "minikube" cluster has been deleted.
18? Successfully deleted profile "minikube"
19$ minikube start --cpus 4 --memory 8192
20? minikube v1.5.2 on Ubuntu 18.04
21✨ Automatically selected the 'virtualbox' driver (alternates: [none])
22? Creating virtualbox VM (CPUs=4, Memory=8192MB, Disk=20000MB) ...
23? Preparing Kubernetes v1.16.2 on Docker '18.09.9' ...
24? Pulling images ...
25? Launching Kubernetes ...
26⌛ Waiting for: apiserver
27? Done! kubectl is now configured to use "minikube"
28```
29
302. kubectl apply
31
32```bash
33$ kubectl apply -f app-deployment.yaml,app-service.yaml,mysql-claim0-persistentvolumeclaim.yaml,mysql-deployment.yaml,mysql-service.yaml
34deployment.apps/app configured
35service/app configured
36persistentvolumeclaim/mysql-claim0 configured
37deployment.apps/mysql configured
38service/mysql configured
39
40```
41
423. kubectl get deployments --watch
43Opcja `watch` pozwala na obserwowanie dostępności deploymentów.
44```bash
45$ kubectl get deployments --watch
46NAME READY UP-TO-DATE AVAILABLE AGE
47app 0/1 1 0 4s
48mysql 0/1 1 0 4s
49app 1/1 1 1 15s
50mysql 1/1 1 1 36s
51```
523. kubectl get pods
53
54```bash
55$ kubectl get pods
56NAME READY STATUS RESTARTS AGE
57app-c969b97f4-r2zwx 1/1 Running 0 96s
58mysql-6d7b4bdc95-cjjgp 1/1 Running 0 96s
59```
60
614. Podglądanie logów
62
63Logi z aplikacji:
64```bash
65$ kubectl logs app-c969b97f4-r2zwx -f
66The application will start in 30s...
67
68 ██╗ ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗
69 ██║ ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
70 ██║ ████████║ ██║ ███████╔╝ ╚█████╗ ██║ ██████╗ ███████╔╝
71 ██╗ ██║ ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║
72 ╚██████╔╝ ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗
73 ╚═════╝ ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝
74
75:: JHipster ? :: Running Spring Boot 2.1.9.RELEASE ::
76:: https://www.jhipster.tech ::
77
782019-12-06 02:01:24.121 INFO 1 --- [ main] i.g.j.s.JhipsterSampleApplicationApp : Starting JhipsterSampleApplicationApp on app-c969b97f4-r2zwx with PID 1 (/app.jar started by root in /)
792019-12-06 02:01:24.126 INFO 1 --- [ main] i.g.j.s.JhipsterSampleApplicationApp : The following profiles are active: prod,swagger
802019-12-06 02:01:35.880 WARN 1 --- [ main] i.g.j.c.liquibase.AsyncSpringLiquibase : Warning, Liquibase took more than 5 seconds to start up!
812019-12-06 02:01:42.187 INFO 1 --- [ main] i.g.j.sample.config.WebConfigurer : Web application configuration, using profiles: prod
822019-12-06 02:01:42.189 INFO 1 --- [ main] i.g.j.sample.config.WebConfigurer : Web application fully configured
832019-12-06 02:01:49.117 INFO 1 --- [ main] i.g.j.s.JhipsterSampleApplicationApp : Started JhipsterSampleApplicationApp in 26.852 seconds (JVM running for 28.524)
842019-12-06 02:01:49.128 INFO 1 --- [ main] i.g.j.s.JhipsterSampleApplicationApp :
85----------------------------------------------------------
86 Application 'jhipsterSampleApplication' is running! Access URLs:
87 Local: http://localhost:8080/
88 External: http://172.17.0.6:8080/
89 Profile(s): [prod, swagger]
90----------------------------------------------------------
91```
92
93Logi z bazy:
94```bash
95$ kubectl logs mysql-6d7b4bdc95-cjjgp -f
96Initializing database
972019-12-06T02:01:11.066935Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
982019-12-06T02:01:11.067050Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.17) initializing of server in progress as process 30
992019-12-06T02:01:12.968406Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
1002019-12-06T02:01:14.733585Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.17) initializing of server has completed
101Database initialized
102Initializing certificates
103Generating a RSA private key
104..........+++++
105..................+++++
106unable to write 'random state'
107writing new private key to 'ca-key.pem'
108-----
109Generating a RSA private key
110.................+++++
111.......+++++
112unable to write 'random state'
113writing new private key to 'server-key.pem'
114-----
115Generating a RSA private key
116............................+++++
117.........................................+++++
118unable to write 'random state'
119writing new private key to 'client-key.pem'
120-----
121Certificates initialized
122MySQL init process in progress...
123MySQL init process in progress...
1242019-12-06T02:01:16.477825Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
1252019-12-06T02:01:16.478138Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 102
1262019-12-06T02:01:17.103118Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
1272019-12-06T02:01:17.138310Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.17' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
1282019-12-06T02:01:17.165190Z 0 [Warning] [MY-011302] [Server] Plugin mysqlx reported: 'Failed at SSL configuration: "SSL context is not usable without certificate and private key"'
1292019-12-06T02:01:17.166661Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
130Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
131Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
132Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
133Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
134
1352019-12-06T02:01:25.147231Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.17) MySQL Community Server - GPL.
136
137MySQL init process done. Ready for start up.
138
1392019-12-06T02:01:25.550148Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
1402019-12-06T02:01:25.550283Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 1
1412019-12-06T02:01:26.061266Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
1422019-12-06T02:01:26.095954Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.17' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
1432019-12-06T02:01:26.208802Z 0 [Warning] [MY-011302] [Server] Plugin mysqlx reported: 'Failed at SSL configuration: "SSL context is not usable without certificate and private key"'
1442019-12-06T02:01:26.210736Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
145mys
146```
147
1485. Sprawdzanie IP minikube
149```bash
150$ minikube ip
151192.168.99.104
152```
153
1546. Sprawdzanie IP aplikacji
155Widać, że aplikacja nie ma zewnętrznego portu
156```bash
157$ kubectl get svc
158NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
159app ClusterIP 10.101.188.164 <none> 8080/TCP 6m27s
160kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8m9s
161mysql ClusterIP 10.100.203.167 <none> 3306/TCP 6m27s
162```
163
1647. Wystawienie adresu aplikacji `app`
165```bash
166$ kubectl expose deployment app --type=NodePort --name app-exposed
167service/app-exposed exposed
168```
169
1708. Sprawdzenie IP wystawionej aplikacji
171```bash
172$ kubectl get svc
173NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
174app ClusterIP 10.101.188.164 <none> 8080/TCP 8m54s
175app-exposed NodePort 10.98.72.64 <none> 8080:31800/TCP 38s
176kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10m
177mysql ClusterIP 10.100.203.167 <none> 3306/TCP 8m54s
178```
179
1809. Adres aplikacji
181Adres aplikacji jest złożeniem IP minikube i portu `app-exposed`:
182http://192.168.99.104:31800/
183
184
185## Stop
186
187```bash
188$ minikube stop
189```
190
191---
192
193Zadanie:
194Uruchom swoją aplikację (testowaną wcześniej w ́środowisku Docker) w środowisku minikube. Wykorzystaj przygotowane wcześniej kontenery.
195
196Wykonane kroki:
197
1981. Instalacja [Kompose](https://github.com/kubernetes/kompose)
199Kompose to narzędzie tłumaczące pliki Docker Compose na zasoby Kubernetesa.
200
201```bash
202# Linux
203curl -L https://github.com/kubernetes/kompose/releases/download/v1.19.0/kompose-linux-amd64 -o kompose
204
205# macOS
206curl -L https://github.com/kubernetes/kompose/releases/download/v1.19.0/kompose-darwin-amd64 -o kompose
207
208chmod +x kompose
209sudo mv ./kompose /usr/local/bin/kompose
210```
211
2122. Konwersja głównego pliku app.yml
213
214```bash
215$ kompose convert -f app.yml
216WARN Volume mount on the host "~/volumes/jhipster/jhipsterSampleApplication/mysql/" isn't supported - ignoring path on the host
217INFO Kubernetes file "app-service.yaml" created
218INFO Kubernetes file "mysql-service.yaml" created
219INFO Kubernetes file "app-deployment.yaml" created
220INFO Kubernetes file "mysql-deployment.yaml" created
221INFO Kubernetes file "mysql-claim0-persistentvolumeclaim.yaml" created
222```
223
2243. Edycja plików app-deployment.yaml i mysql-deployment.yaml
225Pliki należy edytować, ponieważ narzędzie Kompose do konwersji konwertuje do wersji API, która nie jest wspierana przez kubectl:
226
227`app-deployment.yaml`
228Zamiana:
229```yaml
230apiVersion: extensions/v1beta1 -> apiVersion: apps/v1
231```
232Dodanie do `spec`:
233```yaml
234spec:
235 selector:
236 matchLabels:
237 io.kompose.service: app
238```
239
240`mysql-deployment.yaml`
241Zamiana:
242```yaml
243apiVersion: extensions/v1beta1 -> apiVersion: apps/v1
244```
245Dodanie do `spec`:
246```yaml
247spec:
248 selector:
249 matchLabels:
250 io.kompose.service: mysql
251```