|
| 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