Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab9 #8

Open
wants to merge 4 commits into
base: lab8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions LAB8.md

This file was deleted.

58 changes: 58 additions & 0 deletions LAB9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 9

## k8s

In this lab you need to get familiar with `Kubernetes`. Setup local development environment and prepare a
few manifests for your application.

### 10 points

1. Read about `Kubernetes`:
* [K8s](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
* [K8s components](https://kubernetes.io/docs/concepts/overview/components/)

2. Install `kubectl` and `minikube`:
* [Tools](https://kubernetes.io/docs/tasks/tools/)

3. Deploy your application in the `minikube`. Use the `kubectl` create command to create a `Deployment`:
* [Example](https://kubernetes.io/docs/tutorials/hello-minikube/#create-a-deployment)
* [Overview](https://kubernetes.io/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro/)

4. Make your application accessible from outside the `Kubernetes` virtual network. Create a `Service` for it:
* [Example](https://kubernetes.io/docs/tutorials/hello-minikube/#create-a-service) -
* [Overview](https://kubernetes.io/docs/tutorials/kubernetes-basics/expose/expose-intro/)

5. Create a `k8s` folder in your repository and create a `README.md` report inside, provide the output of
`kubectl get pods,svc` command.

6. Clean up. Remove `deployment` and `service` that you created.

7. As you see it wasn't convenient way to manage your app. Use configuration files to deploy your application. Create a `deployment.yml` manifest for it. Set up at least 3 replicas:
* [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
* [Declarative Management of Kubernetes Objects Using Configuration Files](https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/)

8. Create a `service.yml` manifest for your app.
* [Service](https://kubernetes.io/docs/concepts/services-networking/service/)

9. Provide those files in the `k8s` folder. Also provide the output of `kubectl get pods,svc` command in
the report. Provide output of `minikube service --all` command and result from your browser. The screenshot for the latter should show the same IP as in the `minikube service --all` output.

10. Create a PR to the forked repo lab8 branch, ask your teammates to review it and review PRs of your teammates.

11. Create a PR in your own repository from the lab9 branch to the lab8 one. It will help us with grading.

### List of requirements

* `deployment.yml`
* `service.yml`
* output of `kubectl get pods,svc` in README.md in the `k8s` folder
* output of `minikube service --all` in README.md in the `k8s` folder
* screenshot from a browser that shows the same ip as in the latter command.

## Bonus

### 2 points

1. Create `deployment` and `service` manifests for your extra app.

2. Read about `Ingress, Ingress controller, StatefulSet, DaemonSet, PersistentVolumes`, provide the explanation in a nutshell, as you understand it. No copy paste.
59 changes: 59 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Manual approach

```
$ kubectl get pods,svc

NAME READY STATUS RESTARTS AGE
pod/python-app-869dc76fc7-tkj7t 1/1 Running 0 45s

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 66s
service/python-app LoadBalancer 10.106.114.165 <pending> 8080:30398/TCP 16s
```

# Config approach

```
$ kubectl get pods,svc

NAME READY STATUS RESTARTS AGE
pod/python-app-deployment-7dd784648c-9mg78 1/1 Running 0 75s
pod/python-app-deployment-7dd784648c-jldvb 1/1 Running 0 75s
pod/python-app-deployment-7dd784648c-lnbcz 1/1 Running 0 75s

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13m
service/python-app LoadBalancer 10.108.134.239 <pending> 8080:31471/TCP 75s
```

```
$ minikube service --all

|-----------|------------|-------------|--------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------|-------------|--------------|
| default | kubernetes | | No node port |
|-----------|------------|-------------|--------------|
😿 service default/kubernetes has no node port
|-----------|------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------|-------------|---------------------------|
| default | python-app | 8080 | http://192.168.49.2:31471 |
|-----------|------------|-------------|---------------------------|
🏃 Starting tunnel for service kubernetes.
🏃 Starting tunnel for service python-app.
|-----------|------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------|-------------|------------------------|
| default | kubernetes | | http://127.0.0.1:54335 |
| default | python-app | | http://127.0.0.1:54337 |
|-----------|------------|-------------|------------------------|
🎉 Opening service default/kubernetes in default browser...
🎉 Opening service default/python-app in default browser...
❗ Because you are using a Docker driver on windows, the terminal needs to be open to run it.
```

## Screenshot

![Screenshot](screenshot.png)

21 changes: 21 additions & 0 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: python-app-deployment
labels:
app: python-app
spec:
replicas: 3
selector:
matchLabels:
app: python-app
template:
metadata:
labels:
app: python-app
spec:
containers:
- name: python-app
image: draeston/devops_app:latest
ports:
- containerPort: 8080
Binary file added k8s/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions k8s/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: python-app
labels:
app: python-app
spec:
selector:
app: python-app
type: LoadBalancer
ports:
- protocol: TCP
port: 8080
targetPort: 3000