├── LICENSE ├── README.md ├── first-k8s-app ├── Dockerfile ├── README.md ├── index.html └── kube │ ├── app.yaml │ └── namespace.yaml ├── v2.0.0 ├── Dockerfile ├── README.md ├── deployment.yaml └── index.html └── v3.0.0 ├── Dockerfile ├── README.md ├── deployment.yaml └── index.html /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Learnk8s 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes first steps 2 | 3 | This repository contains the supplementary files used in the course "Kubernetes first steps". 4 | 5 | - [You can find the solution for deploying the first app end-to-end here.](first-k8s-app/README.md) 6 | - [The solution for the second lab.](v2.0.0/README.md) 7 | - [The solution for the third lab.](v3.0.0/README.md) 8 | -------------------------------------------------------------------------------- /first-k8s-app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.19.5 2 | 3 | EXPOSE 80 4 | COPY index.html /usr/share/nginx/html 5 | 6 | CMD ["nginx", "-g", "daemon off;"] -------------------------------------------------------------------------------- /first-k8s-app/README.md: -------------------------------------------------------------------------------- 1 | # Packaging and deploying in Kubernetes 2 | 3 | You can create the Docker image for the following application with: 4 | 5 | ```bash 6 | docker build -t /first-k8s-app:1.0.0 . 7 | ``` 8 | 9 | You can push the image to the Docker Hub registry with: 10 | 11 | ```bash 12 | docker push /first-k8s-app:1.0.0 13 | ``` 14 | 15 | Start your minikube cluster with: 16 | 17 | ```bash 18 | minikube start --vm 19 | ``` 20 | 21 | Enable the Ingress add-on with: 22 | 23 | ```bash 24 | minikube addons enable ingress 25 | ``` 26 | 27 | Deploy all of the resources with: 28 | 29 | ```bash 30 | kubectl apply -f kube 31 | ``` 32 | 33 | Retrieve the IP address of minikube with: 34 | 35 | ```bash 36 | minikube ip 37 | ``` 38 | 39 | Visit the application at `http:///second` 40 | -------------------------------------------------------------------------------- /first-k8s-app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | v1.0.0 4 | 5 | 12 |

v1.0.0

13 | 14 | -------------------------------------------------------------------------------- /first-k8s-app/kube/app.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: app 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | name: app 10 | template: 11 | metadata: 12 | labels: 13 | name: app 14 | spec: 15 | containers: 16 | - name: app 17 | image: learnk8s/first-k8s-app:1.0.0 18 | ports: 19 | - containerPort: 80 20 | imagePullPolicy: Always 21 | --- 22 | apiVersion: v1 23 | kind: Service 24 | metadata: 25 | name: app 26 | spec: 27 | selector: 28 | name: app 29 | ports: 30 | - port: 8080 31 | targetPort: 80 32 | --- 33 | apiVersion: networking.k8s.io/v1 34 | kind: Ingress 35 | metadata: 36 | name: app 37 | annotations: 38 | nginx.ingress.kubernetes.io/rewrite-target: / 39 | spec: 40 | rules: 41 | - http: 42 | paths: 43 | - path: /second 44 | pathType: Prefix 45 | backend: 46 | service: 47 | name: app 48 | port: 49 | number: 8080 50 | -------------------------------------------------------------------------------- /first-k8s-app/kube/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: first-k8s-app -------------------------------------------------------------------------------- /v2.0.0/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.19.5 2 | 3 | EXPOSE 80 4 | COPY index.html /usr/share/nginx/html 5 | 6 | CMD ["nginx", "-g", "daemon off;"] -------------------------------------------------------------------------------- /v2.0.0/README.md: -------------------------------------------------------------------------------- 1 | # Deploying Version 2.0.0 2 | 3 | Start your minikube cluster with: 4 | 5 | ```bash 6 | minikube start --vm 7 | ``` 8 | 9 | Enable the Ingress add-on with: 10 | 11 | ```bash 12 | minikube addons enable ingress 13 | ``` 14 | 15 | Instead of uploading the Docker image to a registry, you can create the image in the cluster directly. 16 | 17 | Connect to the Docker daemon inside minikube with: 18 | 19 | ```bash 20 | minikube docker-env 21 | # follow the instructions in the output 22 | ``` 23 | 24 | You Docker CLI is connected to the Docker daemon inside minikube. 25 | 26 | You can create the Docker image with: 27 | 28 | ```bash 29 | docker build -t labv2 . 30 | ``` 31 | 32 | Create a namespace with: 33 | 34 | ```bash 35 | kubectl create namespace labv2 36 | ``` 37 | 38 | Deploy all of the resources with: 39 | 40 | ```bash 41 | kubectl apply -f deployment.yaml --namespace labv2 42 | ``` 43 | 44 | Retrieve the IP address of minikube with: 45 | 46 | ```bash 47 | minikube ip 48 | ``` 49 | 50 | Visit the application at `http:///v2` 51 | -------------------------------------------------------------------------------- /v2.0.0/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: lab2 5 | --- 6 | apiVersion: apps/v1 7 | kind: Deployment 8 | metadata: 9 | name: app 10 | namespace: lab2 11 | spec: 12 | replicas: 1 13 | selector: 14 | matchLabels: 15 | name: app 16 | template: 17 | metadata: 18 | labels: 19 | name: app 20 | spec: 21 | containers: 22 | - name: app 23 | image: labv2 24 | imagePullPolicy: IfNotPresent 25 | ports: 26 | - containerPort: 80 27 | --- 28 | apiVersion: v1 29 | kind: Service 30 | metadata: 31 | name: app 32 | namespace: lab2 33 | spec: 34 | ports: 35 | - nodePort: 32001 36 | port: 80 37 | targetPort: 80 38 | selector: 39 | name: app 40 | type: NodePort 41 | --- 42 | apiVersion: networking.k8s.io/v1 43 | kind: Ingress 44 | metadata: 45 | name: app 46 | namespace: lab2 47 | annotations: 48 | nginx.ingress.kubernetes.io/rewrite-target: / 49 | spec: 50 | rules: 51 | - http: 52 | paths: 53 | - path: /v2 54 | pathType: Prefix 55 | backend: 56 | service: 57 | name: app 58 | port: 59 | number: 80 60 | -------------------------------------------------------------------------------- /v2.0.0/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | v2.0.0 4 | 5 | 13 |

v2.0.0

14 | 15 | -------------------------------------------------------------------------------- /v3.0.0/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8 2 | 3 | WORKDIR /app 4 | 5 | EXPOSE 8000 6 | COPY index.html . 7 | 8 | CMD ["python", "-m", "http.server"] -------------------------------------------------------------------------------- /v3.0.0/README.md: -------------------------------------------------------------------------------- 1 | # Deploying Version 3.0.0 2 | 3 | Start your minikube cluster with: 4 | 5 | ```bash 6 | minikube start --vm 7 | ``` 8 | 9 | Enable the Ingress add-on with: 10 | 11 | ```bash 12 | minikube addons enable ingress 13 | ``` 14 | 15 | Instead of uploading the Docker image to a registry, you can create the image in the cluster directly. 16 | 17 | Connect to the Docker daemon inside minikube with: 18 | 19 | ```bash 20 | minikube docker-env 21 | # follow the instructions in the output 22 | ``` 23 | 24 | You Docker CLI is connected to the Docker daemon inside minikube. 25 | 26 | You can create the Docker image with: 27 | 28 | ```bash 29 | docker build -t labv3 . 30 | ``` 31 | 32 | Create a namespace with: 33 | 34 | ```bash 35 | kubectl create namespace labv3 36 | ``` 37 | 38 | Deploy all of the resources with: 39 | 40 | ```bash 41 | kubectl apply -f deployment.yaml --namespace labv3 42 | ``` 43 | 44 | Retrieve the IP address of minikube with: 45 | 46 | ```bash 47 | minikube ip 48 | ``` 49 | 50 | Check that the application was deployed correctly with: 51 | 52 | ```bash 53 | curl --header 'Host: k8s-is-great.com' http:// 54 | ``` 55 | -------------------------------------------------------------------------------- /v3.0.0/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: lab3 5 | --- 6 | apiVersion: apps/v1 7 | kind: Deployment 8 | metadata: 9 | name: app 10 | namespace: lab3 11 | spec: 12 | replicas: 1 13 | selector: 14 | matchLabels: 15 | name: app 16 | template: 17 | metadata: 18 | labels: 19 | name: app 20 | spec: 21 | containers: 22 | - name: app 23 | image: labv3 24 | imagePullPolicy: IfNotPresent 25 | ports: 26 | - containerPort: 8000 27 | --- 28 | apiVersion: v1 29 | kind: Service 30 | metadata: 31 | name: app 32 | namespace: lab3 33 | spec: 34 | ports: 35 | - nodePort: 32002 36 | port: 80 37 | targetPort: 8000 38 | selector: 39 | name: app 40 | type: NodePort 41 | --- 42 | apiVersion: networking.k8s.io/v1beta1 43 | kind: Ingress 44 | metadata: 45 | name: app 46 | namespace: lab3 47 | annotations: 48 | nginx.ingress.kubernetes.io/rewrite-target: / 49 | spec: 50 | rules: 51 | - host: k8s-is-great.com 52 | http: 53 | paths: 54 | - path: / 55 | pathType: Prefix 56 | backend: 57 | service: 58 | name: app 59 | port: 60 | number: 80 61 | -------------------------------------------------------------------------------- /v3.0.0/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | API 4 | 5 | 13 |

API

14 | 15 | --------------------------------------------------------------------------------