Deploying a Web App with Kubernetes in Kali Linux
Let me show you how easy it is to install k8s and deploy a web app in kali linux. My original idea was to jump to pentesting kubernetes right away. However when I wrote this tutorial to deploy the lab, seemed to me that it was going to be super long. So, expect pentesting kubernetes in a later post.
Kubernetes is an open source container orchestration engine for automating deployment, scaling, and management of containerized applications. The open source project is hosted by the Cloud Native Computing Foundation. Google open-sourced the Kubernetes project in 2014.
Installing Kubernetes and Kubectl
sudo apt-get update && sudo apt-get upgradesudo apt-get install -y apt-transport-https ca-certificates curlsudo curl -fsSLo/usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpgecho "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.listcurl -Ls "https://sbom.k8s.io/$(curl -Ls https://dl.k8s.io/release/latest.txt)/release" | awk '/Package: registry.k8s.io\// {print $3}'sudo apt-get updatesudo apt-get install -y kubectlkubctl version --client --output=yamlInstalling Minikube
sudo curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb sudo dpkg -i minikube_latest_amd64.debminikube startDeploying the WebApp
Creating the configuration files
apiVersion: v1
kind: ConfigMap
metadata:
name: mongo-config
data:
mongo-url: mongo-service
kind: Secret
metadata:
name: mongo-secret
type: Opaque
data:
mongo-user: bW9uZ291c2Vy
mongo-password: bW9uZ29wYXNzd29yZA==
echo -n mongouser | base64echo -n mongopassword | base64apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-deployment
labels:
app: mongo
spec:
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongodb
image: mongo:latest
ports:
- containerPort: 27017
---
apiVersion: v1
kind: Service
metadata:
name: mongo-service
spec:
selector:
app: mongo
ports:
- protocol: TCP
port: 27017
targetPort: 27017
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
labels:
app: webapp
spec:
replicas: 1
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: nanajanashia/k8s-demo-app:v1.0
ports:
- containerPort: 3000
apiVersion: v1
kind: Service
metadata:
name: mongo-service
spec:
selector:
app: mongo
ports:
- protocol: TCP
port: 3000
targetPort: 3000
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-user
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-password
env:
- name: USER_NAME
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-user
- name: USER_PWD
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-password
- name: DB_URL
valueFrom:
configMapKeyRef:
name: mongo-config
key: mongo-url
kubectl apply -f mongo-config.yamlkubectl apply -f mongo-secret.yamlkubectl apply -f mongo.yamlkubectl apply -f webapp.yamlInteracting with our newly created cluster
kubectl get allkubectl get configmapkubectl get secretkubectl get podkubectl logs webapp-deployment-9fccd564d-k6smkkubectl get svcWe can see the port we are going to connect to is port 30100 but to know the IP we have to find the one from the minikube.
minikube ip
Post a Comment