Skip to content

Commit

Permalink
Merge pull request #7 from Otus-DevOps-2023-05/kubernetes-2
Browse files Browse the repository at this point in the history
Kubernetes 2
  • Loading branch information
Baykanurov authored Nov 17, 2023
2 parents 1cb3a9b + 2f3bf60 commit 14d7291
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 17 deletions.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,74 @@ docker-machine rm -f $(docker-machine ls -q)
yc compute instance delete k8s-worker-node
yc compute instance delete k8s-master-node
```
## Kubernetes-2
### Что было сделано:
1. Установил minikube и kubectl
```shell
[22:30:17] baykanurov:baykanurov_microservices git:(kubernetes-2) $ minikube version
minikube version: v1.31.2
commit: fd7ecd9c4599bef9f04c0986c4a0187f98a4396e
[22:32:21] baykanurov:baykanurov_microservices git:(kubernetes-2) $ kubectl version
Client Version: v1.28.3
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.4
```
2. Развернул кластер с помощью minikube на драйвере docker
```shell
minikube start --driver=docker
```
3. Написал deployment и services для приложения reddit
```shell
kubectl apply -f kubernetes/reddit/
```
4. Получил доступ к сервису ui
```shell
minikube service ui
```
5. Развернул аддон для kubernetes dashboard
```shell
minikube addons enable dashboard
minikube dashboard --url 0.0.0.0
```
6. Развернул кластер kubernetes-2-baykanurov через Yandex Cloud
Managed Service for kubernetes
7. Создал группы узлов для данного кластера
8. Подключился к кластеру
```shell
22:50:23] baykanurov:baykanurov_microservices git:(kubernetes-2) $ yc managed-kubernetes cluster get-credentials kubernetes-2-baykanurov --external

Context 'yc-kubernetes-2-baykanurov' was added as default to kubeconfig '/home/baykanurov/.kube/config'.
Check connection to cluster using 'kubectl cluster-info --kubeconfig /home/baykanurov/.kube/config'.

Note, that authentication depends on 'yc' and its config profile 'default'.
To access clusters using the Kubernetes API, please use Kubernetes Service Account.
There is a new yc version '0.113.0' available. Current version: '0.111.0'.
See release notes at https://cloud.yandex.ru/docs/cli/release-notes
You can install it by running the following command in your shell:
$ yc components update
[22:50:32] baykanurov:baykanurov_microservices git:(kubernetes-2) $ kubectl config current-context
yc-kubernetes-2-baykanurov
```
9. Нашёл внешний IP-адрес развернутых нод и порт публикации сервиса UI
```shell
[23:48:07] baykanurov:baykanurov_microservices git:(kubernetes-2) $ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUN
TIME
cl1dc3oohjcqfp5nk94o-oniv Ready <none> 56m v1.24.8 10.128.0.11 158.160.54.62 Ubuntu 20.04.6 LTS 5.4.0-165-generic containerd://
1.6.22
cl1dc3oohjcqfp5nk94o-ybez Ready <none> 56m v1.24.8 10.128.0.31 158.160.109.86 Ubuntu 20.04.6 LTS 5.4.0-165-generic containerd://
1.6.22
[23:48:17] baykanurov:baykanurov_microservices git:(kubernetes-2) $ kubectl describe service ui -n dev | grep NodePort
Type: NodePort
NodePort: <unset> 32092/TCP
```
10. Запустил приложение
```shell
kubectl apply -f ./kubernetes/reddit/dev-namespace.yml
kubectl apply -f ./kubernetes/reddit/ -n dev
```
11. Проверил, что приложение работает на каждой из нод
![img.png](docs/img.png)
![img1.png](docs/img1.png)
P.S. Удалил инстанс кластера т.к. домашние задания проверяются долго, а потребление кластера на YC очень дорогое.
Binary file added docs/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions kubernetes/reddit/comment-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: comment-deployment
name: comment
labels:
app: reddit
component: comment
spec:
replicas: 1
selector:
matchLabels:
app: comment
app: reddit
component: comment
template:
metadata:
name: comment
labels:
app: comment
app: reddit
component: comment
spec:
containers:
- image: baykanurov/comment
name: comment
- image: baykanurov/comment
name: comment
env:
- name: COMMENT_DATABASE_HOST
value: comment-db
18 changes: 18 additions & 0 deletions kubernetes/reddit/comment-mongodb-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: v1
kind: Service
metadata:
name: comment-db
labels:
app: reddit
component: mongo
comment-db: "true"
spec:
ports:
- port: 27017
protocol: TCP
targetPort: 27017
selector:
app: reddit
component: mongo
comment-db: "true"
16 changes: 16 additions & 0 deletions kubernetes/reddit/comment-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Service
metadata:
name: comment
labels:
app: reddit
component: comment
spec:
ports:
- port: 9292
protocol: TCP
targetPort: 9292
selector:
app: reddit
component: comment
5 changes: 5 additions & 0 deletions kubernetes/reddit/dev-namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: dev
25 changes: 20 additions & 5 deletions kubernetes/reddit/mongo-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-deployment
name: mongo
labels:
app: reddit
component: mongo
comment-db: "true"
post-db: "true"
spec:
replicas: 1
selector:
matchLabels:
app: mongo
app: reddit
component: mongo
template:
metadata:
name: mongo
labels:
app: mongo
app: reddit
component: mongo
comment-db: "true"
post-db: "true"
spec:
containers:
- image: mongo:4.4
name: mongo
- image: mongo:4.4
name: mongo
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
volumes:
- name: mongo-persistent-storage
emptyDir: {}
16 changes: 16 additions & 0 deletions kubernetes/reddit/mongodb-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Service
metadata:
name: mongodb
labels:
app: reddit
component: mongo
spec:
ports:
- port: 27017
protocol: TCP
targetPort: 27017
selector:
app: reddit
component: mongo
14 changes: 11 additions & 3 deletions kubernetes/reddit/post-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: post-deployment
name: post
labels:
app: reddit
component: post
spec:
replicas: 1
selector:
matchLabels:
app: post
app: reddit
component: post
template:
metadata:
name: post
labels:
app: post
app: reddit
component: post
spec:
containers:
- image: baykanurov/post
name: post
env:
- name: POST_DATABASE_HOST
value: post-db
18 changes: 18 additions & 0 deletions kubernetes/reddit/post-mongodb-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: v1
kind: Service
metadata:
name: post-db
labels:
app: reddit
component: mongo
post-db: "true"
spec:
ports:
- port: 27017
protocol: TCP
targetPort: 27017
selector:
app: reddit
component: mongo
post-db: "true"
16 changes: 16 additions & 0 deletions kubernetes/reddit/post-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Service
metadata:
name: post
labels:
app: reddit
component: post
spec:
ports:
- port: 5000
protocol: TCP
targetPort: 5000
selector:
app: reddit
component: post
18 changes: 14 additions & 4 deletions kubernetes/reddit/ui-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ui-deployment
name: ui
labels:
app: reddit
component: ui
spec:
replicas: 1
selector:
matchLabels:
app: ui
app: reddit
component: ui
template:
metadata:
name: ui
name: ui-pod
labels:
app: ui
app: reddit
component: ui
spec:
containers:
- image: baykanurov/ui
name: ui
env:
- name: ENV
valueFrom:
fieldRef:
fieldPath: metadata.namespace
18 changes: 18 additions & 0 deletions kubernetes/reddit/ui-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: v1
kind: Service
metadata:
name: ui
labels:
app: reddit
component: ui
spec:
type: NodePort
ports:
- nodePort: 32092
port: 80
protocol: TCP
targetPort: 9292
selector:
app: reddit
component: ui

0 comments on commit 14d7291

Please sign in to comment.