Commit e849fbc6 authored by Muhammad Usman's avatar Muhammad Usman

first commit

parent f9e0e2a9
# K8s lab 2
## Create Three VM's on Virtual Box
https://docs.google.com/document/d/1g88PdeX3zKvhZjNY-j4qnaepZQYY6stnwuRN3VMICEs/edit?usp=sharing
## Install K8s Cluster
https://www.oueta.com/linux/create-a-debian-11-kubernetes-cluster-with-kubeadm/
## When Cluster is fully installed and working pactice service, application
apiVersion: v1
kind: Namespace
metadata:
name: horishop
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: horishop-api
namespace: horishop
spec:
replicas: 2
selector:
matchLabels:
app: horishop-api
template:
metadata:
labels:
app: horishop-api
spec:
containers:
- name: horishop-api
image: usmanbaloch/horishop_api:latest
env:
- name: DB_USER
value: horishop-user
- name: DB_PASSWORD
value: horishop123
- name: DB_NAME
value: horishop
- name: DB_HOST
value: mysql-service.mysql.svc.cluster.local
- name: APP_ENV
value: production
ports:
- containerPort: 5000
imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
labels:
app: horishop-api
name: horishop-api
namespace: horishop
spec:
ports:
- port: 80
protocol: TCP
targetPort: 5000
selector:
app: horishop-api
type: LoadBalancer
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
serviceName: mysql
replicas: 1
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: Always
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-storage
mountPath: /var/lib/mysql
subPath: mysql
env:
- name: MYSQL_USER
value: horishop-user
- name: MYSQL_DATABASE
value: horishop
- name: MYSQL_PASSWORD
value: horishop123
- name: MYSQL_ROOT_PASSWORD
value: ssi@123
volumeClaimTemplates:
- metadata:
name: mysql-storage
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-volume
labels:
type: local
spec:
storageClassName: standard
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: Service
metadata:
name: mysql-service
namespace: mysql
spec:
selector:
app: mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
CREATE TABLE users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
insert into users (firstname,lastname,email) values ('muhammad','usman','usmanm@nisum.com');
# Install metallb on bare-metal cluster
1. kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.5/config/manifests/metallb-native.yaml
```
2. kubectl apply -f metallb.yaml
```
##Reference URL
https://metallb.universe.tf/installation/
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: first-pool
namespace: metallb-system
spec:
addresses:
- 192.168.12.4-192.168.12.10
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: nisum-pool
namespace: metallb-system
spec:
ipAddressPools:
- first-pool
# Test each service one by one
## For ClusterIP run both pods
### try to access pod1 from pod2 and vice verca.
## For NodePort access appliaction from browser or VM shell.
## For Load Balancer first install metallb then apply the manifest.
### test the appliaction from Load Balacer's IP.
apiVersion: v1
kind: Pod
metadata:
name: pod1
labels:
app: pod1
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
name: http-pod1-svc
---
apiVersion: v1
kind: Service
metadata:
name: pod1-service
spec:
selector:
app: pod1
ports:
- name: pod1-port
protocol: TCP
port: 80
targetPort: http-pod1-svc
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
labels:
app: pod2
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
name: http-pod2-svc
---
apiVersion: v1
kind: Service
metadata:
name: pod2-service
spec:
selector:
app: pod2
ports:
- name: pod2-port
protocol: TCP
port: 80
targetPort: http-pod2-svc
apiVersion: apps/v1
kind: Deployment
metadata:
name: lb-ex-deployment
labels:
name: lb-ex
spec:
replicas: 2
selector:
matchLabels:
name: lb-ex
template:
metadata:
labels:
name: lb-ex
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: lb-ex
labels:
name: lb-ex
spec:
selector:
name: lb-ex
ports:
- protocol: TCP
port: 80
name: http
type: LoadBalancer
apiVersion: apps/v1
kind: Deployment
metadata:
name: np-ex-deployment
labels:
name: np-ex
spec:
replicas: 2
selector:
matchLabels:
name: np-ex
template:
metadata:
labels:
name: np-ex
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: np-ex-service
labels:
name: np-ex
spec:
selector:
name: np-ex
ports:
- protocol: TCP
port: 80
name: http
type: NodePort
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment