Skip to content

Commit de87819

Browse files
(DOCSP-9072): Allow PodSpecTemplate for containers to modify the cont… (#219)
* (DOCSP-9072): Allow PodSpecTemplate for containers to modify the container spec and also provide side-car design * (DOCSP-9072): copy review feedback * (DOCSP-9072): tech review feedback
1 parent 3cacf47 commit de87819

File tree

4 files changed

+147
-75
lines changed

4 files changed

+147
-75
lines changed

config/redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ raw: kubernetes-operator/release-notes -> ${base}/stable/release-notes
5050

5151
# v1.3 and earlier
5252
[*-v1.3]: kubernetes-operator/${version}/tutorial/plan-k8s-operator-install -> ${base}/${version}/tutorial/install-k8s-operator
53+
[*-v1.3]: kubernetes-operator/${version}/tutorial/modify-resource-image -> ${base}/${version}/

source/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ optimal performance.
5252
Install the Operator </installation>
5353
Deploy Ops Manager Resources </om-resources>
5454
Deploy MongoDB Database Resources </mdb-resources>
55+
/tutorial/modify-resource-image
5556
/reference
5657
/specification
5758
Release Notes </release-notes>

source/reference/troubleshooting.txt

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -529,78 +529,3 @@ policy through the :opsmgr:`API
529529
further changes through the |onprem| application. However, the
530530
|k8s-op-short| retains any changes you made in the |onprem|
531531
application while features were available.
532-
533-
Tune MongoDB |k8s| Resource Docker Images
534-
-----------------------------------------
535-
536-
|k8s-mdbrsc| Docker images run on Ubuntu and use Ubuntu's default
537-
system configuration. Using the :setting:`spec.podSpec.podTemplate`
538-
setting, add a privileged sidecar :k8sdocs:`init container
539-
</concepts/workloads/pods/init-containers/>` to the |k8s-mdbrsc|
540-
definition to tune the underlying Ubuntu system configuration in the
541-
|k8s-mdbrsc| containers.
542-
543-
.. example::
544-
545-
|k8s-mdbrsc| Docker images use the Ubuntu default ``keepalive`` time
546-
of ``7200``. MongoDB recommends a shorter ``keepalive`` time of ``120``
547-
for database deployments.
548-
549-
You can tune the ``keepalive`` time in the |k8s-mdbrscs| Docker images
550-
if you experience network timeouts or socket errors in communication
551-
between clients and |k8s-mdbrscs|.
552-
553-
To tune |k8s-mdbrsc| Docker images:
554-
555-
1. Update the |k8s-mdbrsc| definition to append a privileged sidecar
556-
container to |k8s-mdbrsc| pods the |k8s-op-short| creates.
557-
558-
The following sample :setting:`spec.podSpec.podTemplate` changes the
559-
``keepalive`` value to the recommended value of ``120``:
560-
561-
.. code-block:: yaml
562-
563-
spec:
564-
podSpec:
565-
podTemplate:
566-
spec:
567-
initContainers:
568-
- name: "apply-sysctl-test"
569-
image: "busybox:latest"
570-
securityContext:
571-
privileged: true
572-
command: ["sysctl", "-w", "net.ipv4.tcp_keepalive_time=120"]
573-
574-
#. Apply the updated resource definition:
575-
576-
.. code-block:: none
577-
578-
kubectl apply -f <database-resource-conf>.yaml -n <namespace>
579-
580-
A privileged sidecar container is added to each |k8s-pod| the
581-
|k8s-op-short| created using the |k8s-mdbrsc| definition.
582-
583-
To verify your changes:
584-
585-
1. Get a shell to a running container in your database resource
586-
|k8s-pod|:
587-
588-
.. code-block:: none
589-
590-
kubectl exec -n <namespace> -it <pod-name> -- /bin/bash
591-
592-
#. Verify your changes are present. Following the example, verify that
593-
the ``keepalive`` time is changed:
594-
595-
.. code-block:: none
596-
597-
cat /proc/sys/net/ipv4/tcp_keepalive_time
598-
599-
Returns:
600-
601-
.. code-block:: none
602-
:copyable: false
603-
604-
120
605-
606-
.. seealso:: :manual:`Operating System Configuration </administration/production-checklist-operations/#linux>` in the MongoDB Manual.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
.. _modify-resource-image:
2+
3+
=========================================================
4+
Modify |onprem| or MongoDB Kubernetes Resource Containers
5+
=========================================================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
You can modify the containers in the |k8s-pods| in which |onprem| and
16+
|k8s-mdbrscs| run using the ``podTemplate`` setting that applies to your
17+
deployment:
18+
19+
- |onprem|: :opsmgrkube:`spec.podSpec.podTemplate`
20+
- MongoDB database: :setting:`spec.podSpec.podTemplate`
21+
22+
To review which fields you can add to a ``podTemplate``, see the
23+
:k8sdocs:`Kubernetes documentation
24+
</reference/generated/kubernetes-api/v1.11/#podspec-v1-core>`.
25+
26+
When you create containers using a ``podTemplate``, the |k8s-op-short|
27+
handles container creation differently based on the ``name`` you provide
28+
for each container in the ``containers`` array:
29+
30+
- If the ``name`` field *matches* the name of the applicable resource
31+
image, the |k8s-op-short| updates the |onprem| or MongoDB database
32+
container in the |k8s-pod| to which the ``podTemplate`` applies:
33+
34+
- |onprem|: ``mongodb-enterprise-ops-manager``
35+
- MongoDB database: ``mongodb-enterprise-database``
36+
37+
- If the ``name`` field *does not match* the name of the applicable
38+
resource image, the |k8s-op-short| creates an InitContainer in each
39+
|k8s-pod| to which the ``podTemplate`` applies.
40+
41+
Define a Volume Mount for a MongoDB Kubernetes Resource
42+
-------------------------------------------------------
43+
44+
On-disk files in containers in |k8s-pods| don't survive container
45+
crashes or restarts. Using the :setting:`spec.podSpec.podTemplate`
46+
setting, you can add a :k8sdocs:`volume mount
47+
</concepts/storage/volumes/>` to persist data for the life of the
48+
|k8s-pod|.
49+
50+
To create a volume mount:
51+
52+
1. Update the |k8s-mdbrsc| definition to include a volume mount for
53+
containers in the |k8s-mdbrsc| pods the |k8s-op-short| creates.
54+
55+
The following sample :setting:`spec.podSpec.podTemplate` defines
56+
a volume mount:
57+
58+
.. code-block:: yaml
59+
60+
podSpec:
61+
podTemplate:
62+
spec:
63+
containers:
64+
- name: mongod-enterprise-database
65+
volumeMounts:
66+
- mountPath: /data
67+
name: survives-restart
68+
volumes:
69+
- name: survives-restart
70+
emptyDir: {}
71+
72+
#. Apply the updated resource definition:
73+
74+
.. code-block:: none
75+
76+
kubectl apply -f <database-resource-conf>.yaml -n <namespace>
77+
78+
Tune MongoDB MongoDB Kubernetes Resource Docker Images with an InitContainer
79+
----------------------------------------------------------------------------
80+
81+
|k8s-mdbrsc| Docker images run on Ubuntu and use Ubuntu's default
82+
system configuration. To tune the underlying Ubuntu system configuration
83+
in the |k8s-mdbrsc| containers, use the :setting:`spec.podSpec.podTemplate`
84+
setting to add a privileged InitContainer :k8sdocs:`init container
85+
</concepts/workloads/pods/init-containers/>` to the |k8s-mdbrsc|
86+
definition.
87+
88+
.. example::
89+
90+
|k8s-mdbrsc| Docker images use the Ubuntu default ``keepalive`` time
91+
of ``7200``. MongoDB recommends a shorter ``keepalive`` time of ``120``
92+
for database deployments.
93+
94+
You can tune the ``keepalive`` time in the |k8s-mdbrscs| Docker images
95+
if you experience network timeouts or socket errors in communication
96+
between clients and |k8s-mdbrscs|.
97+
98+
.. seealso:: :manual:`Does TCP keepalive time affect MongoDB Deployments? </faq/diagnostics/#does-tcp-keepalive-time-affect-mongodb-deployments>` in the MongoDB Manual
99+
100+
To tune |k8s-mdbrsc| Docker images:
101+
102+
1. Update the |k8s-mdbrsc| definition to append a privileged
103+
InitContainer to |k8s-mdbrsc| pods the |k8s-op-short| creates.
104+
105+
The following sample :setting:`spec.podSpec.podTemplate` changes the
106+
``keepalive`` value to the recommended value of ``120``:
107+
108+
.. code-block:: yaml
109+
110+
spec:
111+
podSpec:
112+
podTemplate:
113+
spec:
114+
initContainers:
115+
- name: "adjust-tcp-keepalive"
116+
image: "busybox:latest"
117+
securityContext:
118+
privileged: true
119+
command: ["sysctl", "-w", "net.ipv4.tcp_keepalive_time=120"]
120+
121+
#. Apply the updated resource definition:
122+
123+
.. code-block:: none
124+
125+
kubectl apply -f <database-resource-conf>.yaml -n <namespace>
126+
127+
A privileged InitContainer is added to each |k8s-pod| the |k8s-op-short|
128+
creates using the |k8s-mdbrsc| definition.
129+
130+
Open a shell session to a running container in your database resource
131+
|k8s-pod| and verify your changes. For the ``keepalive`` example above,
132+
use the following command to get the current ``keepalive`` value:
133+
134+
.. code-block:: none
135+
136+
kubectl exec -n <namespace> -it <pod-name> -- cat /proc/sys/net/ipv4/tcp_keepalive_time
137+
138+
Returns:
139+
140+
.. code-block:: none
141+
:copyable: false
142+
143+
120
144+
145+
.. seealso:: :manual:`Operating System Configuration </administration/production-checklist-operations/#linux>` in the MongoDB Manual.

0 commit comments

Comments
 (0)