mirror of
https://github.com/slurm-personal/school-dev-k8s.git
synced 2026-06-27 13:50:24 +00:00
Add basic info
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
### Resources and Probes
|
||||
|
||||
Создаем deployment с ресурсами и пробами
|
||||
|
||||
```bash
|
||||
kubectl apply -f deployment-with-stuff.yaml
|
||||
```
|
||||
|
||||
Смотрим что получилось
|
||||
|
||||
```bash
|
||||
kubectl get pod
|
||||
```
|
||||
|
||||
Должны увидеть что-то типа такого:
|
||||
|
||||
```bash
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
my-deployment-69695544f6-v97jr 1/1 Running 0 20s
|
||||
my-deployment-69695544f6-xcpq9 1/1 Running 0 20s
|
||||
```
|
||||
|
||||
Поменяем специально Readiness Probe на заведомо неверную в манифесте и применим его снова
|
||||
|
||||
```bash
|
||||
vim deployment-with-stuff.yaml
|
||||
kubectl apply -f deployment-with-stuff.yaml
|
||||
```
|
||||
|
||||
Смотрим что получилось
|
||||
|
||||
```bash
|
||||
kubectl get pod
|
||||
```
|
||||
|
||||
Видим что pod'ы не переходят в статус `1/1 Running`. Смотрим describe pod'а:
|
||||
```bash
|
||||
kubectl describe po my-deployment-845d88fdcf-9bd29
|
||||
```
|
||||
Чистим за собой кластер
|
||||
```bash
|
||||
kubectl delete deployment --all
|
||||
```
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
# file: practice/1.kube-basics-lecture/4.resources-and-probes/deployment-with-stuff.yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: my-app
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 1
|
||||
maxUnavailable: 1
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: my-app
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.12
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
readinessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
periodSeconds: 10
|
||||
successThreshold: 1
|
||||
timeoutSeconds: 1
|
||||
livenessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
periodSeconds: 10
|
||||
successThreshold: 1
|
||||
timeoutSeconds: 1
|
||||
initialDelaySeconds: 10
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
failureThreshold: 30
|
||||
periodSeconds: 10
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 100Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 100Mi
|
||||
...
|
||||
@@ -0,0 +1,87 @@
|
||||
## Смотрим на Service'ы Kubernetes'а
|
||||
|
||||
1) Деплоим "основное" приложение
|
||||
|
||||
```bash
|
||||
cd ~/slurm/practice/5.network-abstractions/2.ingress-and-services/
|
||||
|
||||
kubectl apply -f app
|
||||
```
|
||||
|
||||
2) Запустим тестовое приложение, с которого мы будем обращаться к основному:
|
||||
|
||||
```bash
|
||||
kubectl run test --image=amouat/network-utils -it bash
|
||||
|
||||
exit
|
||||
```
|
||||
|
||||
3) Создаем Service типа ClusterIP:
|
||||
|
||||
```bash
|
||||
kubectl apply -f clusterip.yaml
|
||||
```
|
||||
|
||||
4) Убедимся, что Service работает. Узнаем его IP, зайдем внутрь нашего тестового Pod'а и обратимся к основному приложению, используя имя сервиса и IP:
|
||||
|
||||
```bash
|
||||
kubectl get svc
|
||||
kubectl exec test -it bash
|
||||
|
||||
curl <ip-адрес сервиса>
|
||||
curl my-service
|
||||
|
||||
exit
|
||||
```
|
||||
|
||||
5) Создаем Service типа Nodeport:
|
||||
|
||||
```bash
|
||||
kubectl apply -f nodeport.yaml
|
||||
```
|
||||
|
||||
6) Проверяем что все ОК. Смотрим наши Service'ы, находим NodePort. Фиксируем, какой порт нам открылся и проверяем работу Service'а:
|
||||
|
||||
```bash
|
||||
kubectl get svc
|
||||
|
||||
curl node-1.slurm.io:<свой номер порта>
|
||||
|
||||
curl master-1.slurm.io:<свой номер порта>
|
||||
```
|
||||
|
||||
7) Создаем Service LoadBalancer:
|
||||
|
||||
```bash
|
||||
kubectl create -f loadbalancer.yaml
|
||||
|
||||
kubectl get svc
|
||||
```
|
||||
|
||||
8) Подчищаем за собой:
|
||||
|
||||
```bash
|
||||
kubectl delete svc my-service-lb my-service-np
|
||||
```
|
||||
|
||||
## Разбираемся с Ingress'ами
|
||||
|
||||
1) Создадим Ingress без указания хоста:
|
||||
|
||||
```bash
|
||||
kubectl apply -f nginx-ingress.yaml
|
||||
kubectl get ing
|
||||
```
|
||||
|
||||
2) Попробуем покурлить разные домены:
|
||||
|
||||
```bash
|
||||
curl my.s<свой номер логина>.k8s.slurm.io
|
||||
|
||||
curl notmy.s<свой номер логина>.k8s.slurm.io
|
||||
```
|
||||
|
||||
**САМОСТОЯТЕЛЬНАЯ РАБОТА:**
|
||||
- Подправить Ingress таким образом, чтобы он работал только на домене `my.s<свой номер логина>.k8s.slurm.io`
|
||||
|
||||
Правильный ответ лежит в `right_answers/`
|
||||
@@ -0,0 +1,15 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: my-configmap
|
||||
data:
|
||||
default.conf: |
|
||||
server {
|
||||
listen 80 default_server;
|
||||
server_name _;
|
||||
default_type text/plain;
|
||||
|
||||
location / {
|
||||
return 200 '$hostname\n';
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: my-app
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 1
|
||||
maxUnavailable: 1
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: my-app
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.12
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
readinessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
periodSeconds: 10
|
||||
successThreshold: 1
|
||||
timeoutSeconds: 1
|
||||
livenessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
periodSeconds: 10
|
||||
successThreshold: 1
|
||||
timeoutSeconds: 1
|
||||
initialDelaySeconds: 10
|
||||
resources:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 100Mi
|
||||
limits:
|
||||
cpu: 10m
|
||||
memory: 100Mi
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /etc/nginx/conf.d/
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: my-configmap
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-service
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: my-app
|
||||
type: ClusterIP
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-service-lb
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: my-app
|
||||
type: LoadBalancer
|
||||
@@ -0,0 +1,17 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: my-ingress-nginx
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "nginx"
|
||||
spec:
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: my-service
|
||||
port:
|
||||
number: 80
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-service-np
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: my-app
|
||||
type: NodePort
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: my-ingress-nginx
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "nginx"
|
||||
spec:
|
||||
rules:
|
||||
- host: my.s<свой номер логина>.k8s.slurm.io
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: my-service
|
||||
port:
|
||||
number: 80
|
||||
Reference in New Issue
Block a user