🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 5 Min Lesezeit
0

Deploying PostgreSQL, MySQL, and MongoDB on Kubernetes: A Step-by-Step Guide

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Kubernetes has become the go-to platform for managing containerized applications at scale. If you're looking to run popular databases like PostgreSQL, MySQL, and MongoDB in a Kubernetes environment, this guide will show you how to deploy, connect, and interact with these databases. We will walk through deploying each database in its own Pod, exposing them using Kubernetes Services, and performing basic SQL operations.






Prerequisites



Before diving in, ensure you have the following:




  • A running Kubernetes cluster.

  • kubectl installed and configured to interact with the cluster.

  • Helm installed (optional but recommended for installing the databases easily).






Step 1: Create the my-lab Namespace



We’ll create a dedicated namespace for deploying all the databases. This will keep things organized and separate from other workloads in your cluster.




CODE
kubectl create namespace my-lab









Step 2: Deploy PostgreSQL in the my-lab Namespace



We’ll use Helm to deploy PostgreSQL from the Bitnami repository. Helm makes it easier to manage Kubernetes applications.



2.1. Add the Bitnami Helm repository:




CODE
helm repo add bitnami https://charts.bitnami.com/bitnami






2.2. Install PostgreSQL:




CODE
helm install my-postgres bitnami/postgresql --namespace my-lab






2.3. Check the status of the PostgreSQL Pod:




CODE
kubectl get pods --namespace my-lab






2.4. Retrieve the PostgreSQL password (we will use this to authenticate when connecting to PostgreSQL):




CODE
kubectl get secret --namespace my-lab my-postgres-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode






Save this password for the next steps. It will be used for connecting to PostgreSQL.






Step 3: Deploy MySQL in the my-lab Namespace



Next, we'll deploy MySQL using a similar process.



3.1. Install MySQL using Helm:




CODE
helm install my-mysql bitnami/mysql --namespace my-lab






3.2. Check the MySQL Pod’s status:




CODE
kubectl get pods --namespace my-lab






3.3. Retrieve the MySQL root password:




CODE
kubectl get secret --namespace my-lab my-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode









Step 4: Deploy MongoDB in the my-lab Namespace



We’ll now deploy MongoDB using Helm:



4.1. Install MongoDB with Helm:




CODE
helm install my-mongo bitnami/mongodb --namespace my-lab






4.2. Check the MongoDB Pod status:




CODE
kubectl get pods --namespace my-lab






4.3. Retrieve the MongoDB root password:




CODE
kubectl get secret --namespace my-lab my-mongo-mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 --decode









Step 5: Expose Databases for Local Access Using kubectl port-forward



To interact with the databases from your local machine, we'll use kubectl port-forward. This allows you to expose the database services locally without modifying the Kubernetes cluster's networking.



5.1 Port Forward PostgreSQL



Run the following command to expose PostgreSQL locally on port 5732:




CODE
kubectl port-forward svc/my-postgres-postgresql 5732:5432 --namespace my-lab






PostgreSQL will now be accessible at localhost:5732.



5.2 Port Forward MySQL



Similarly, expose MySQL locally on port 3706:




CODE
kubectl port-forward svc/my-mysql 3706:3306 --namespace my-lab






MySQL will now be accessible at localhost:3706.



5.3 Port Forward MongoDB



Expose MongoDB locally on port 27717:




CODE
kubectl port-forward svc/my-mongo-mongodb 27717:27017 --namespace my-lab






MongoDB will now be accessible at localhost:27717.






Step 6: Connect to the Databases and Perform SQL Operations



Now that the databases are deployed and exposed, let’s connect to each one and perform basic database operations like creating tables, inserting data, and querying data.



6.1 PostgreSQL



To connect to PostgreSQL, use the psql command-line tool:




CODE
psql -h localhost -p 5732 -U postgres -d postgres






Enter the password you retrieved earlier.



Once connected, you can create a table, insert data, and query the database:




CODE
-- Create a table
CREATE TABLE employees (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
position VARCHAR(100)
);

-- Insert some data
INSERT INTO employees (name, position) VALUES ('Alice', 'Manager');
INSERT INTO employees (name, position) VALUES ('Bob', 'Developer');

-- Retrieve data
SELECT * FROM employees;






6.2 MySQL



To connect to MySQL, use the mysql client:



Start a bash shell in the MySQL Pod:




CODE
kubectl exec -it my-mysql-0 -n my-lab -- bash






Connect to MySQL:




CODE
mysql -u root -p






Enter the root password you retrieved earlier.



Once inside MySQL, you can create a database, create a table, insert data, and query:




CODE
-- Create a database
CREATE DATABASE d_test;

-- Use the database
USE d_test;

-- Create a table
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
position VARCHAR(100)
);

-- Insert data
INSERT INTO employees (name, position) VALUES ('Alice', 'Manager');
INSERT INTO employees (name, position) VALUES ('Bob', 'Developer');

-- Retrieve data
SELECT * FROM employees;






6.3 MongoDB



To connect to MongoDB, use the mongosh shell:




CODE
kubectl exec -it <mongo-pod-name> -n my-lab -- mongosh -u root -p






Once connected, perform basic CRUD operations:




CODE
// Switch to the database
use mydb;

// Create a collection
db.createCollection('employees');

// Insert some data
db.employees.insert({ name: 'Alice', position: 'Manager' });
db.employees.insert({ name: 'Bob', position: 'Developer' });

// Retrieve data
db.employees.find();









Final Notes



The kubectl port-forward method is great for local development and testing, but for production environments, you’ll want to expose your databases using proper Kubernetes Services and Ingress controllers.



The default configuration provided by Helm charts works for basic deployments. If you need persistence, high availability, or custom configurations, you should customize the Helm charts or use Kubernetes manifests.



While this guide covers PostgreSQL, MySQL, and MongoDB, Kubernetes is a flexible platform, and you can easily swap these databases for other types like MariaDB, Redis, or even more complex setups.



Deploying and managing databases on Kubernetes is a great way to leverage the scalability and resiliency of Kubernetes, while still using familiar relational and NoSQL databases.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Deploying PostgreSQL, MySQL, and MongoDB on Kubernetes: A Step-by-Step Guide

Thematisch verwandte Begriffe: Deploying, PostgreSQL, MySQL, MongoDB · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...