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

Replicaset #19

Open
wants to merge 4 commits into
base: master
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
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Stage 1: Build PHP application
FROM php:7.4-apache

# Set environment variables
ENV PHP_UPLOAD_MAX_FILESIZE 10M
ENV PHP_POST_MAX_SIZE 10M

# Install MySQL client
RUN apt-get update && apt-get install -y default-mysql-client

# Install mysqli and pdo_mysql extensions
RUN docker-php-ext-install mysqli pdo_mysql

# Copy your source code to /var/www/html
COPY . /var/www/html

# Configure Apache
COPY apache-config.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Expose port 80
EXPOSE 80

# Start Apache
CMD ["apache2-foreground"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,13 @@ sudo sed -i 's/172.20.1.101/localhost/g' /var/www/html/index.php
```
curl http://localhost
```

### Delete a Replicaset

```sh
kubectl describe -f rs/go-demo-2.yml

kubectl delete replicaset <name of replicaset> --cascade=orphan

```

15 changes: 15 additions & 0 deletions configmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-initdb-config
data:
initdb.sql: |
CREATE TABLE friends (
id INT,
name VARCHAR(256),
age INT,
gender VARCHAR(3)
);
INSERT INTO friends VALUES (1, 'John Smith', 32, 'm');
INSERT INTO friends VALUES (2, 'Lilian Worksmith', 29, 'f');
INSERT INTO friends VALUES (3, 'Michael Rupert', 27, 'm');
25 changes: 25 additions & 0 deletions dockerfile.ms1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Stage 1: Build Stage
FROM php:7.4-apache AS build

# Install mysqli extension
RUN docker-php-ext-install mysqli

# Stage 2: Production Stage
FROM php:7.4-apache

# Copy the built mysqli extension from the build stage
COPY --from=build /usr/local/lib/php/extensions/no-debug-non-zts-20190902/mysqli.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/mysqli.so

# Enable the mysqli extension
RUN echo "extension=mysqli.so" > /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini

# Copy source code to /var/www/html
COPY src/ /var/www/html/

# Update database connection string to point to the Kubernetes service named mysql-service
# Assuming the connection is in a PHP file, you may need to replace the appropriate string
# Example: If your connection string is in config.php
# RUN sed -i 's/old_connection_string/new_connection_string/g' /var/www/html/config.php

# Expose port 80
EXPOSE 80
16 changes: 16 additions & 0 deletions dockerfile.ms2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Stage 1: Build environment for installing dependencies
FROM php:7.4-apache AS builder

RUN apt-get update && apt-get install -y mysqli && apt-get clean

# Stage 2: Copy application code and configure database connection
FROM php:7.4-apache

# Copy source code to Apache document root
COPY . /var/www/html

# Update database connection string (replace 'config.php' with your actual file)
RUN sed -i 's/DATABASE_HOST.*/DATABASE_HOST=mysql-service/g' /var/www/html/config.php

# Expose port 80 for web traffic
EXPOSE 80
17 changes: 17 additions & 0 deletions mysql-initdb-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
name: mysql
spec:
containers:
- name: mysql
image: mysql
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-initdb
mountPath: /docker-entrypoint-initdb.d
volumes:
- name: mysql-initdb
configMap:
name: mysql-initdb-config