A pod definition file or a template file can be used to define a pod. Below is a
pod specification that creates a single container and mounts the nfs volume for
read-write access:
Example 3. Pod Object Definition
apiVersion: v1
kind: Pod
metadata:
name: hello-openshift-nfs-pod (1)
labels:
name: hello-openshift-nfs-pod
spec:
containers:
- name: hello-openshift-nfs-pod
image: openshift/hello-openshift (2)
ports:
- name: web
containerPort: 80
volumeMounts:
- name: nfsvol (3)
mountPath: /usr/share/nginx/html (4)
securityContext:
supplementalGroups: [100003] (5)
privileged: false
volumes:
- name: nfsvol
persistentVolumeClaim:
claimName: nfs-pvc (6)
1 |
The name of this pod as displayed by oc get pod . |
2 |
The image run by this pod. |
3 |
The name of the volume. This name must be the same in both the containers and volumes sections. |
4 |
The mount path as seen in the container. |
5 |
The group ID to be assigned to the container. |
6 |
The PVC that was created in the previous step. |
Save the pod definition to a file, for example nfs.yaml, and create the pod:
# oc create -f nfs.yaml
pod "hello-openshift-nfs-pod" created
Verify that the pod was created:
# oc get pods
NAME READY STATUS RESTARTS AGE
hello-openshift-nfs-pod 1/1 Running 0 4s
More details are shown in the oc describe pod
command:
[root@ose70 nfs]# oc describe pod hello-openshift-nfs-pod
Name: hello-openshift-nfs-pod
Namespace: default (1)
Image(s): fedora/S3
Node: ose70.rh7/192.168.234.148 (2)
Start Time: Mon, 21 Mar 2016 09:59:47 -0400
Labels: name=hello-openshift-nfs-pod
Status: Running
Reason:
Message:
IP: 10.1.0.4
Replication Controllers: <none>
Containers:
hello-openshift-nfs-pod:
Container ID: docker://a3292104d6c28d9cf49f440b2967a0fc5583540fc3b062db598557b93893bc6f
Image: fedora/S3
Image ID: docker://403d268c640894cbd76d84a1de3995d2549a93af51c8e16e89842e4c3ed6a00a
QoS Tier:
cpu: BestEffort
memory: BestEffort
State: Running
Started: Mon, 21 Mar 2016 09:59:49 -0400
Ready: True
Restart Count: 0
Environment Variables:
Conditions:
Type Status
Ready True
Volumes:
nfsvol:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: nfs-pvc (3)
ReadOnly: false
default-token-a06zb:
Type: Secret (a secret that should populate this volume)
SecretName: default-token-a06zb
Events: (4)
FirstSeen LastSeen Count From SubobjectPath Reason Message
───────── ──────── ───── ──── ───────────── ────── ───────
4m 4m 1 {scheduler } Scheduled Successfully assigned hello-openshift-nfs-pod to ose70.rh7
4m 4m 1 {kubelet ose70.rh7} implicitly required container POD Pulled Container image "openshift3/ose-pod:v3.1.0.4" already present on machine
4m 4m 1 {kubelet ose70.rh7} implicitly required container POD Created Created with docker id 866a37108041
4m 4m 1 {kubelet ose70.rh7} implicitly required container POD Started Started with docker id 866a37108041
4m 4m 1 {kubelet ose70.rh7} spec.containers{hello-openshift-nfs-pod} Pulled Container image "fedora/S3" already present on machine
4m 4m 1 {kubelet ose70.rh7} spec.containers{hello-openshift-nfs-pod} Created Created with docker id a3292104d6c2
4m 4m 1 {kubelet ose70.rh7} spec.containers{hello-openshift-nfs-pod} Started Started with docker id a3292104d6c2
1 |
The project (namespace) name. |
2 |
The IP address of the OKD node running the pod. |
3 |
The PVC name used by the pod. |
4 |
The list of events resulting in the pod being launched and the nfs volume being
mounted. The container will not start correctly if the volume cannot mount. |
There is more internal information, including the SCC used to authorize the pod,
the pod’s user and group IDs, the SELinux label, and more, shown in the oc get
pod <name> -o yaml
command:
[root@ose70 nfs]# oc get pod hello-openshift-nfs-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
openshift.io/scc: restricted (1)
creationTimestamp: 2016-03-21T13:59:47Z
labels:
name: hello-openshift-nfs-pod
name: hello-openshift-nfs-pod
namespace: default (2)
resourceVersion: "2814411"
selflink: /api/v1/namespaces/default/pods/hello-openshift-nfs-pod
uid: 2c22d2ea-ef6d-11e5-adc7-000c2900f1e3
spec:
containers:
- image: fedora/S3
imagePullPolicy: IfNotPresent
name: hello-openshift-nfs-pod
ports:
- containerPort: 80
name: web
protocol: TCP
resources: {}
securityContext:
privileged: false
terminationMessagePath: /dev/termination-log
volumeMounts:
- mountPath: /usr/share/S3/html
name: nfsvol
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-a06zb
readOnly: true
dnsPolicy: ClusterFirst
host: ose70.rh7
imagePullSecrets:
- name: default-dockercfg-xvdew
nodeName: ose70.rh7
restartPolicy: Always
securityContext:
supplementalGroups:
- 100003 (3)
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
volumes:
- name: nfsvol
persistentVolumeClaim:
claimName: nfs-pvc (4)
- name: default-token-a06zb
secret:
secretName: default-token-a06zb
status:
conditions:
- lastProbeTime: null
lastTransitionTime: 2016-03-21T13:59:49Z
status: "True"
type: Ready
containerStatuses:
- containerID: docker://a3292104d6c28d9cf49f440b2967a0fc5583540fc3b062db598557b93893bc6f
image: fedora/S3
imageID: docker://403d268c640894cbd76d84a1de3995d2549a93af51c8e16e89842e4c3ed6a00a
lastState: {}
name: hello-openshift-nfs-pod
ready: true
restartCount: 0
state:
running:
startedAt: 2016-03-21T13:59:49Z
hostIP: 192.168.234.148
phase: Running
podIP: 10.1.0.4
startTime: 2016-03-21T13:59:47Z
1 |
The SCC used by the pod. |
2 |
The project (namespace) name. |
3 |
The supplemental group ID for the pod (all containers). |
4 |
The PVC name used by the pod. |