Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop v0.01 #59

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions README2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
To include the installation and setup of the PostgreSQL charm in your Kubernetes (k8s) cluster using Ubuntu Multipass and a `charm-dev` blueprint, follow these steps:

### Prerequisites
Ensure you have the following installed on your host machine:
- Ubuntu Multipass
- Juju (for deploying charms)
- MicroK8s (or any other Kubernetes distribution)

### Step 1: Create and configure the `charm-dev` Multipass instance

If you haven't already set up a `charm-dev` instance, you can create one using the following command:

```bash
multipass launch --name charm-dev --cpus 2 --mem 4G --disk 20G
```

### Step 2: Access the `charm-dev` instance

```bash
multipass shell charm-dev
```

### Step 3: Install and configure MicroK8s

Inside the `charm-dev` instance, install MicroK8s:

```bash
sudo snap install microk8s --classic
```

Add the current user to the `microk8s` group to avoid needing `sudo`:

```bash
sudo usermod -a -G microk8s $USER
newgrp microk8s
```

Enable the necessary MicroK8s addons:

```bash
microk8s enable dns storage
```

### Step 4: Install Juju

Install Juju on the `charm-dev` instance:

```bash
sudo snap install juju --classic
```

### Step 5: Bootstrap Juju on MicroK8s

Bootstrap Juju to use MicroK8s as the Kubernetes provider:

```bash
juju bootstrap microk8s microk8s-controller
```

### Step 6: Add a model for PostgreSQL

Create a new Juju model for PostgreSQL:

```bash
juju add-model postgresql-model
```

### Step 7: Deploy the PostgreSQL charm

Deploy the PostgreSQL charm using Juju:

```bash
juju deploy postgresql-k8s
```

### Step 8: Verify the deployment

Check the status of the deployment to ensure everything is running correctly:

```bash
juju status
```

### Step 9: Configuring PostgreSQL (Optional)

If you need to configure PostgreSQL, you can use Juju configuration options. For example, to set a custom database name:

```bash
juju config postgresql-k8s database-name=mydatabase
```

### Automating the Setup

To automate these steps in your `charm-dev` blueprint, you can use cloud-init to provision the `charm-dev` instance with the necessary packages and configurations. Create a cloud-init configuration file (e.g., `cloud-init.yaml`) with the following content:

```yaml
#cloud-config
packages:
- snapd

runcmd:
- snap install microk8s --classic
- usermod -a -G microk8s ubuntu
- newgrp microk8s
- microk8s enable dns storage
- snap install juju --classic
- juju bootstrap microk8s microk8s-controller
- juju add-model postgresql-model
- juju deploy postgresql-k8s
- juju config postgresql-k8s database-name=mydatabase
```

### Step 10: Launch the Multipass instance with cloud-init

Launch the `charm-dev` instance with the cloud-init configuration:

```bash
multipass launch --name charm-dev --cpus 2 --mem 4G --disk 20G --cloud-init cloud-init.yaml
```

This will set up the instance, install MicroK8s and Juju, bootstrap Juju, create a model, and deploy the PostgreSQL charm automatically.

### Summary

By following these steps, you can set up a Kubernetes cluster with a PostgreSQL database using Ubuntu Multipass and Juju charms. The cloud-init configuration automates the process, making it easy to replicate the setup in future environments.
61 changes: 61 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
### Use cloud-init conf.yaml for multipass VM setup

## Charm-Dev
multipass launch --cpus 4 --memory 8G --disk 50G --name my-vm charm-dev

## FullStack (using --cloud-init to use local yaml)
multipass launch --cpus 4 --memory 8G --disk 50G --name fullstack --cloud-init ~/dev/multipass-blueprints/v1/fullstack-dev.yaml


#############
## TODO
#############


### Deployed on k8s
-apollo server graphql
-apollo router

#######################



postgres password: zx0HkZCdtnt5fEL6
replication password: pARMByIYyYbLNwCq



juju ssh --container postgresql postgresql-k8s/leader bash

################
postgres IP:
10.152.183.69
################

### View database list using password of currently logged in
psql --host=10.152.183.69 --username=operator --password --list

### Output
root@postgresql-k8s-0:/# psql --host=10.152.183.69 --username=operator --password --list
Password:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+---------+--------------------------
postgres | operator | UTF8 | C | C.UTF-8 | operator=CTc/operator +
| | | | | backup=CTc/operator +
| | | | | replication=CTc/operator+
| | | | | rewind=CTc/operator +
| | | | | monitoring=CTc/operator +
| | | | | admin=c/operator
template0 | operator | UTF8 | C | C.UTF-8 | =c/operator +
| | | | | operator=CTc/operator
template1 | operator | UTF8 | C | C.UTF-8 | =c/operator +
| | | | | operator=CTc/operator
(3 rows)


### Execute commands against databse
psql --host=10.152.183.69 --username=operator --password postgres

[Service]
Environment="MULTIPASS_BLUEPRINTS_URL=https://github.com/SolutionsExcite/multipass-blueprints/archive/refs/heads/develop-v0.01.zip"
8 changes: 8 additions & 0 deletions scripts/1-create-fullstack-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

multipass launch \
--cpus 4 \
--memory 8G \
--disk 50G \
--name fullstack-dev \
charm-dev
38 changes: 38 additions & 0 deletions scripts/add-helm3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Install Helm if not already installed
if ! command -v helm &> /dev/null
then
echo "Helm not found. Installing Helm."
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
else
echo "Helm is already installed."
fi

# Ensure microk8s is up and running
echo "Ensuring MicroK8s is ready..."
microk8s status --wait-ready

# Enable necessary MicroK8s services
echo "Enabling MicroK8s services..."
microk8s enable helm3
microk8s enable dns
microk8s enable storage

# Ensure helm is pointing to microk8s
echo "Setting up Helm to use MicroK8s..."
microk8s helm3 repo update

# Add the Apollo Router Helm repository
echo "Adding Apollo Router Helm repository..."
helm repo add apollo-router oci://ghcr.io/apollographql/helm-charts

# Update Helm repositories
echo "Updating Helm repositories..."
helm repo update

# Install Apollo Router using Helm
echo "Installing Apollo Router..."
helm install apollo-router apollo-router/router

echo "Apollo Router installation complete."
33 changes: 33 additions & 0 deletions scripts/create-person-table.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

juju run postgresql-k8s/leader get-password


juju ssh --container postgresql postgresql-k8s/leader bash


psql -U your_username -d your_database -f sql/create_person.sql
psql --host=10.1.188.213 --username=operator --password --list
psql --host=10.1.188.213 --username=operator --password postgres



CREATE DATABASE fullstack;

## example
CREATE TABLE mytable (
id SERIAL PRIMARY KEY,
name VARCHAR(50),
age INT
);

CREATE TABLE person (
id SERIAL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL
);

## temp password: qIohj3q5D5BQksrf

## add mock data
INSERT INTO person (first_name) VALUES ('John');
INSERT INTO person (first_name) VALUES ('Jane');
28 changes: 28 additions & 0 deletions scripts/deploy-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#qIohj3q5D5BQksrf

snap add helm



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



# bootstrap juju to use the local LXD controller
juju bootstrap localhost overlord

# create model for PostreSQL K8s name 'tutorial'
juju add-model tutorial

# check status
juju status

# Documentation: https://canonical.com/data/docs/postgresql/k8s/t-deploy
# deploy postgres charm for microk8s
juju deploy postgresql-k8s --trust

# watch deployment status
#juju status --watch 1s


4 changes: 4 additions & 0 deletions scripts/sql/create_person.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE person (
id SERIAL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL
);
Loading