Skip to content

Commit

Permalink
Merge pull request #2954 from AndrewBulah/md-sa2-30-24
Browse files Browse the repository at this point in the history
12.k8s
  • Loading branch information
pluhin authored Feb 10, 2025
2 parents 122f8d8 + 7fa2cff commit 89ef2b1
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 0 deletions.
Binary file added Andrew_Bulakh/12.Kubernetes.Data.Security/1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Andrew_Bulakh/12.Kubernetes.Data.Security/3.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 Andrew_Bulakh/12.Kubernetes.Data.Security/4.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions Andrew_Bulakh/12.Kubernetes.Data.Security/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# 12. Kubernetes. Data. Security

## Homework Assignment 1. Config maps and secrets

deployment.yaml
```bash
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 4
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
initContainers:
- name: init-config
image: busybox
command:
- sh
- -c
- |
cp /config/index.html /usr/share/nginx/html/index.html && \
sed -i "s/{{ .Values.hostname }}/$HOSTNAME/g" /usr-share/nginx/html/index.html
volumeMounts:
- name: config-volume
mountPath: /config
- name: www-volume
mountPath: /usr/share/nginx/html
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
volumeMounts:
- name: www-volume
mountPath: /usr/share/nginx/html
- name: ssh-keys
mountPath: /root/.ssh # Монтируем секреты в директорию /root/.ssh
- name: nginx-config
mountPath: /etc/nginx/nginx.conf # Монтируем конфигурацию Nginx
subPath: nginx.conf
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "250m"
memory: "256Mi"
lifecycle:
postStart:
exec:
command: ["sh", "-c", "nginx -s reload"]
volumes:
- name: config-volume
configMap:
name: nginx-index
- name: www-volume
emptyDir: {}
- name: ssh-keys
secret:
secretName: ssh-keys
- name: nginx-config
configMap:
name: nginx-config
```

service.yaml
```bash
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort
```

ingress.yaml
```bash
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: nginx-test.k8s-1.sa
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
```

nginx.conf
```bash
server {
listen 80;
server_name nginx-test.k8s-1.sa;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
```
index.html
```bash
<!DOCTYPE html>
<html>
<head>
<title>Host Info</title>
</head>
<body>
<h1>Hostname: {{ .Values.hostname }}</h1>
</body>
</html>
```

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 89ef2b1

Please sign in to comment.