-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersistentVolumeinKubernetes
More file actions
82 lines (68 loc) · 2.49 KB
/
Copy pathPersistentVolumeinKubernetes
File metadata and controls
82 lines (68 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
QUESTION:
The Nautilus DevOps team is working on a Kubernetes template to deploy a web application on the cluster. There are some requirements to create/use persistent volumes to store the application code, and the template needs to be designed accordingly. Please find more details below:
Create a PersistentVolume named as pv-nautilus. Configure the spec as storage class should be manual, set capacity to 5Gi, set access mode to ReadWriteOnce, volume type should be hostPath and set path to /mnt/itadmin (this directory is already created, you might not be able to access it directly, so you need not to worry about it).
Create a PersistentVolumeClaim named as pvc-nautilus. Configure the spec as storage class should be manual, request 2Gi of the storage, set access mode to ReadWriteOnce.
Create a pod named as pod-nautilus, mount the persistent volume you created with claim name pvc-nautilus at document root of the web server, the container within the pod should be named as container-nautilus using image httpd with latest tag only (remember to mention the tag i.e httpd:latest).
Create a node port type service named web-nautilus using node port 30008 to expose the web server running within the pod.
Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
SOLUTION
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-nautilus
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
capacity:
storage: 5Gi
hostPath:
path: /mnt/itadmin
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nautilus
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata:
name: pod-nautilus
labels:
app: my-pod-nautilus
spec:
containers:
- image: httpd:latest
name: container-nautilus
ports:
- containerPort: 80
volumeMounts:
- mountPath: /var/www/html
name: storage-nautilus
volumes:
- name: storage-nautilus
persistentVolumeClaim:
claimName: pvc-nautilus
---
apiVersion: v1
kind: Service
metadata:
name: web-nautilus
spec:
type: NodePort
selector:
app: my-pod-nautilus
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30008
Though, I earlier had an issue, which was that I didnt link the pod to the Nodeport in the service .yaml file, hence, I could not access the webserver.
Error was corrected using the selector in the service