{"id":411,"date":"2024-06-17T17:01:41","date_gmt":"2024-06-18T00:01:41","guid":{"rendered":"http:\/\/184.72.63.26\/?p=411"},"modified":"2024-06-18T22:28:20","modified_gmt":"2024-06-19T05:28:20","slug":"deploy-mongodb-and-mongo-express-on-kubernetes-cluster","status":"publish","type":"post","link":"https:\/\/www.wallacel.com\/index.php\/2024\/06\/17\/deploy-mongodb-and-mongo-express-on-kubernetes-cluster\/","title":{"rendered":"Deploy MongoDB and Mongo Express on Kubernetes Cluster"},"content":{"rendered":"\n<p>In this setup guide, I will deploy a MongoDB and Mongo Express application on AWS Kubernetes Cluster (EKS). EKS is a managed Kubernetes service that makes it easier to run Kubernetes on AWS. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"481\" height=\"351\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/eks-5.png\" alt=\"\" class=\"wp-image-534\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/eks-5.png 481w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/eks-5-300x219.png 300w\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" \/><\/figure>\n\n\n\n<p>Using EKS offers the following major benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pre-install Kubernetes master nodes and other apps like container runtime for you<\/li>\n\n\n\n<li>Master nodes are managed by AWS so you can focus on worker nodes<\/li>\n\n\n\n<li>Service are deployed across multiple Availability Zones to ensure high availability<\/li>\n\n\n\n<li>Automatic scaling by adjusting the number of work nodes in the cluster<\/li>\n<\/ul>\n\n\n\n<p>Kubernetes (K8s) is an open source platform to deploy, scale and manage containerized applications. Here my setup is to deploy a MongoDB database and Mongo Express application using their docker images from <a href=\"https:\/\/hub.docker.com\/\" data-type=\"link\" data-id=\"https:\/\/hub.docker.com\/\">Docker Hub<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Objectives:<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"809\" height=\"351\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/mongodb-3.png\" alt=\"\" class=\"wp-image-535\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/mongodb-3.png 809w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/mongodb-3-300x130.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/mongodb-3-768x333.png 768w\" sizes=\"auto, (max-width: 809px) 100vw, 809px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create EKS Cluster using <strong><code data-enlighter-language=\"bat\" class=\"EnlighterJSRAW\">eksctl<\/code><\/strong> command<\/li>\n\n\n\n<li>Create MongoDB deployment and service using <strong><code data-enlighter-language=\"bat\" class=\"EnlighterJSRAW\">kubectl<\/code><\/strong> command<\/li>\n\n\n\n<li>Create Mongo Express deployment and service using <strong><strong><code data-enlighter-language=\"bat\" class=\"EnlighterJSRAW\">kubectl<\/code><\/strong><\/strong> command<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install eksctl command<\/h2>\n\n\n\n<p>In my previous <a href=\"http:\/\/184.72.63.26\/index.php\/2024\/05\/29\/provision-an-eks-cluster-using-terraform\/\" data-type=\"link\" data-id=\"http:\/\/184.72.63.26\/index.php\/2024\/05\/29\/provision-an-eks-cluster-using-terraform\/\">blog<\/a>, I already explored how to create an EKS cluster using Terraform. This time I will use an open source CLI tool <strong><code data-enlighter-language=\"bat\" class=\"EnlighterJSRAW\">eksctl<\/code><\/strong> to create my EKS cluster. It automatically creates the necessary AWS resources (e.g. VPC, Subnets, Security Group, Node Group, etc.) required with a single command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"788\" height=\"410\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/eksctl.png\" alt=\"\" class=\"wp-image-414\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/eksctl.png 788w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/eksctl-300x156.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/eksctl-768x400.png 768w\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" \/><\/figure>\n\n\n\n<p>This will Install the eksctl command on MacOS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">brew tap weaveworks\/tap\nbrew install weaveworks\/tap\/eksctl<\/code><\/pre>\n\n\n\n<p>Prepare a parameter file (<strong>eks-cluster.yaml<\/strong>) for creating my EKS Cluster. It contains a node group with two EC2 instances of type <strong>t2.micro<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: eksctl.io\/v1alpha5\nkind: ClusterConfig\n\nmetadata:\n  name: mongo-cluster\n  region: ca-central-1\n\nnodeGroups:\n  - name: linux\n    instanceType: t2.micro\n    desiredCapacity: 2\n    privateNetworking: true<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% eksctl create cluster -f eks-cluster.yaml<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"330\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-62.png\" alt=\"\" class=\"wp-image-417\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-62.png 877w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-62-300x113.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-62-768x289.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"610\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-64.png\" alt=\"\" class=\"wp-image-419\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-64.png 877w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-64-300x209.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-64-768x534.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<p>Use the following command to check my cluster is created.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl get nodes<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"58\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-66.png\" alt=\"\" class=\"wp-image-421\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-66.png 728w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-66-300x24.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Deploy MongoDB<\/h2>\n\n\n\n<p>We will be using the latest MongoDB official docker <a href=\"https:\/\/hub.docker.com\/_\/mongo\">image<\/a>. There are two environment variables we need to setup <code>MONGO_INITDB_ROOT_USERNAME<\/code>, <code>MONGO_INITDB_ROOT_PASSWORD<\/code> and I will store them in a secret file instead of hardcoding in the configuration file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"782\" height=\"267\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-67.png\" alt=\"\" class=\"wp-image-424\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-67.png 782w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-67-300x102.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-67-768x262.png 768w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/figure>\n\n\n\n<p>In order to store the user name and password in a secret configuration file, first we need to encode their values from plain text to base64. For example, my user name is &#8216;<code>root<\/code>&#8216; and password is &#8216;<code>myrootpassword<\/code>&#8216;, the commands are as follow.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% echo -n 'root' | base64\n\ncm9vdA==\n\n% echo -n 'myrootpassword' | base64\n\nbXlyb290cGFzc3dvcmQ=<\/code><\/pre>\n\n\n\n<p>My <strong>secrets.yaml<\/strong> looks like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: v1\nkind: Secret\nmetadata:\n    name: mongodb-secrets\ntype: Opaque\ndata:\n    mongodb-root-username: cm9vdA==\n    mongodb-root-password: bXlyb290cGFzc3dvcmQ=<\/code><\/pre>\n\n\n\n<p>Create the secrets in Kubernetes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl apply -f <strong>secrets.yaml<\/strong>\n% kubectl get secret<\/code><\/pre>\n\n\n\n<p>Now we can prepare our MongoDB deployment file (<strong>mongo.yaml<\/strong>) and reference the user name and password from the Kubernetes secrets.<\/p>\n\n\n\n<p>Explanation: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>image: mongo &#8211; name of the docker image<\/li>\n\n\n\n<li>containerPort: 27017 &#8211; standard port no. that Mongo DB server listens on<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: eks-mongodb-deployment\n  labels:\n    app: mongodb\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: mongodb\n  template:\n    metadata:\n      labels:\n        app: mongodb\n    spec:\n      containers:\n      - name: mongodb\n        image: mongo\n        ports:\n        - containerPort: 27017\n        env:\n        - name: MONGO_INITDB_ROOT_USERNAME\n          valueFrom:\n            secretKeyRef:\n              name: mongodb-secrets\n              key: mongodb-root-username\n        - name: MONGO_INITDB_ROOT_PASSWORD\n          valueFrom: \n            secretKeyRef:\n              name: mongodb-secrets\n              key: mongodb-root-password<\/code><\/pre>\n\n\n\n<p>Now we can deploy our MongoDB pod<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl apply -f mongo.yaml\n% kubectl get pod\n% kubectl describe pod <em>&lt;pod-name&gt;<\/em><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"922\" height=\"325\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-68.png\" alt=\"\" class=\"wp-image-426\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-68.png 922w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-68-300x106.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-68-768x271.png 768w\" sizes=\"auto, (max-width: 922px) 100vw, 922px\" \/><\/figure>\n\n\n\n<p>Next, we will create an internal service for other pods (e.g. Mongo Express) to talk to the MongoDB server we just created.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"195\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/mongodb-svc-1-1.png\" alt=\"\" class=\"wp-image-536\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/mongodb-svc-1-1.png 357w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/mongodb-svc-1-1-300x164.png 300w\" sizes=\"auto, (max-width: 357px) 100vw, 357px\" \/><\/figure>\n\n\n\n<p>Our MongoDB service file (<strong>mongosvc.yaml<\/strong>) looks like this.<\/p>\n\n\n\n<p>Explanation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>selector: app: mongodb &#8211; specify the pod this service will attach to<\/li>\n\n\n\n<li>targetPort: 27017 &#8211; match the container port no. of MongoDB deployment<\/li>\n\n\n\n<li>port: 27017 &#8211; port no. this service listens on<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: v1\nkind: Service\nmetadata:\n  name: mongodb-service\nspec:\n  selector:\n    app: mongodb\n  ports:\n    - protocol: TCP\n      port: 27017\n      targetPort: 27017<\/code><\/pre>\n\n\n\n<p>Now we can create our MondoDB internal service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl apply -f mongosvc.yaml\n% kubectl get service<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"612\" height=\"120\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-70.png\" alt=\"\" class=\"wp-image-428\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-70.png 612w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-70-300x59.png 300w\" sizes=\"auto, (max-width: 612px) 100vw, 612px\" \/><\/figure>\n\n\n\n<p>To verify the service is attached to the correct MongoDB pod, check the IP and Port no. of our service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl describe service mongodb-service\n% kubectl get pod -o wide<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"928\" height=\"324\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-71.png\" alt=\"\" class=\"wp-image-430\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-71.png 928w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-71-300x105.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-71-768x268.png 768w\" sizes=\"auto, (max-width: 928px) 100vw, 928px\" \/><\/figure>\n\n\n\n<p>Here the <strong>Endpoints<\/strong> of our service is showing <strong><code>192.168.83.54:27017<\/code><\/strong>, which matches the internal IP address of our MongoDB pod name <strong><code>eks-mongodb-deployment-67f4f7cddf-2hccf<\/code><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Deploy Mongo Express<\/h2>\n\n\n\n<p>Mongo Express is a web-based MongoDB admin interface written in Node.js, Express.js and Bootstrap 3. We will prepare a deployment file to deploy this app to our EKS cluster. Again, we are using the official docker image from <a href=\"https:\/\/hub.docker.com\/_\/mongo-express\">dockerhub<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"276\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-72.png\" alt=\"\" class=\"wp-image-431\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-72.png 752w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-72-300x110.png 300w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/figure>\n\n\n\n<p>There are three environment variables that we need to configure for this app:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ME_CONFIG_MONGODB_ADMINUSERNAME<\/code><\/li>\n\n\n\n<li><code>ME_CONFIG_MONGODB_ADMINPASSWORD<\/code><\/li>\n\n\n\n<li><code>ME_CONFIG_MONGODB_SERVER<\/code><\/li>\n<\/ul>\n\n\n\n<p>We will use the same username and password defined in our MongoDB setup and that are already stored as Kubernetes secrets. We need to tell Mongo Express the database server to connect to by specifying the internal service name (i.e. <strong>mongodb-service<\/strong>) in the <code>ME_CONFIG_MONGODB_SERVER<\/code> variable.<\/p>\n\n\n\n<p>Let&#8217;s create a Kubernetes ConfigMap (<strong>configmap.yaml<\/strong>) to store this environment configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: mongodb-configmap\ndata:\n  database_server: mongodb-service<\/code><\/pre>\n\n\n\n<p>Create the config map in Kubernetes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl apply -f configmap.yaml\n% kubectl get configmap<\/code><\/pre>\n\n\n\n<p>Prepare the deployment file (<strong>express.yaml<\/strong>) for Mongo Express.<\/p>\n\n\n\n<p>Explanation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>containerPort: 8081 &#8211; standard port no. that Mongo Express listens on<\/li>\n\n\n\n<li>configMapKeyRef: name: mongodb-configmap &#8211; reference the environment variable from ConfigMap<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: eks-mongo-express-deployment\n  labels:\n    app: mongo-express\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: mongo-express\n  template:\n    metadata:\n      labels:\n        app: mongo-express\n    spec:\n      containers:\n      - name: mongo-express\n        image: mongo-express\n        ports:\n        - containerPort: 8081\n        env:\n        - name: ME_CONFIG_MONGODB_ADMINUSERNAME\n          valueFrom:\n            secretKeyRef:\n              name: mongodb-secrets\n              key: mongodb-root-username\n        - name: ME_CONFIG_MONGODB_ADMINPASSWORD\n          valueFrom: \n            secretKeyRef:\n              name: mongodb-secrets\n              key: mongodb-root-password\n        - name: ME_CONFIG_MONGODB_SERVER\n          valueFrom: \n            configMapKeyRef:\n              name: mongodb-configmap\n              key: database_server<\/code><\/pre>\n\n\n\n<p>Deploy our Mongo Express pod<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl apply -f express.yaml\n% kubectl get pod\n% kubectl describe pod <em>&lt;mongo_express_pod_name&gt;<\/em><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"929\" height=\"328\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-73.png\" alt=\"\" class=\"wp-image-433\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-73.png 929w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-73-300x106.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-73-768x271.png 768w\" sizes=\"auto, (max-width: 929px) 100vw, 929px\" \/><\/figure>\n\n\n\n<p>Our final step is to allow access to Mongo Express through browser by creating an external service.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"746\" height=\"195\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/express-svc-2.png\" alt=\"\" class=\"wp-image-537\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/express-svc-2.png 746w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/express-svc-2-300x78.png 300w\" sizes=\"auto, (max-width: 746px) 100vw, 746px\" \/><\/figure>\n\n\n\n<p>Our Mongo Express service configuration file (<strong>expresssvc.yaml<\/strong>) looks like this.<\/p>\n\n\n\n<p>Explanation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>type: LoadBalance &#8211; allows to accept external request by assigning an external IP address<\/li>\n\n\n\n<li>nodePort: 30000 &#8211; port no. for the external IP address to listen on<\/li>\n\n\n\n<li>targetPort: 8081 &#8211; match the container port no. of Mongo Express deployment<\/li>\n\n\n\n<li>port: 8081 &#8211; port no. this service listens on<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: v1\nkind: Service\nmetadata:\n  name: mongo-express-service\nspec:\n  selector:\n    app: mongo-express\n  type: LoadBalancer  \n  ports:\n    - protocol: TCP\n      port: 8081\n      targetPort: 8081\n      nodePort: 30000<\/code><\/pre>\n\n\n\n<p>Deploy our external service for Mongo Express.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">% kubectl apply -f expresssvc.yaml\n% kubectl get service<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"925\" height=\"187\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-75.png\" alt=\"\" class=\"wp-image-436\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-75.png 925w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-75-300x61.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-75-768x155.png 768w\" sizes=\"auto, (max-width: 925px) 100vw, 925px\" \/><\/figure>\n\n\n\n<p>An external IP is automatically assigned to the mongo-express-service just created. We can now access the Mongo Express UI from our browser (first login are &#8220;<code>admin<\/code>&#8221; for username and &#8220;<code>pass<\/code>&#8221; for password).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"974\" height=\"940\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-76.png\" alt=\"\" class=\"wp-image-437\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-76.png 974w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-76-300x290.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-76-768x741.png 768w\" sizes=\"auto, (max-width: 974px) 100vw, 974px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"966\" height=\"576\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-77.png\" alt=\"\" class=\"wp-image-438\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-77.png 966w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-77-300x179.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-77-768x458.png 768w\" sizes=\"auto, (max-width: 966px) 100vw, 966px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Clean Up<\/h2>\n\n\n\n<p>Resources created in this guide will incur charges if you keep them running. We can easily delete the EKS cluster and all its resources (e.g. EC2 instances, VPC, subnets, node group, etc.) with the <strong><strong><code data-enlighter-language=\"bat\" class=\"EnlighterJSRAW\">eksctl<\/code><\/strong><\/strong> command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">% eksctl delete cluster --name &lt;cluster name&gt;<\/code><\/pre>\n\n\n\n<p>Thank you for reading my article, you can find all the configuration files in my <a href=\"https:\/\/github.com\/wallylee99\/mongodb-eks\">GitHub<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this setup guide, I will deploy a MongoDB and Mongo Express application on AWS Kubernetes Cluster (EKS). EKS is a managed Kubernetes service that makes it easier to run Kubernetes on AWS. Using EKS offers the following major benefits: Kubernetes (K8s) is an open source platform to deploy, scale and manage containerized applications. Here [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":457,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[31,32,23,33],"class_list":["post-411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","tag-docker","tag-eks","tag-kubernetes","tag-mongodb"],"_links":{"self":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/comments?post=411"}],"version-history":[{"count":37,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/411\/revisions"}],"predecessor-version":[{"id":538,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/411\/revisions\/538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media\/457"}],"wp:attachment":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media?parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/categories?post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/tags?post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}