Skip to content

Commit

Permalink
added migrate from pod identity and spring boot docs
Browse files Browse the repository at this point in the history
  • Loading branch information
naman-msft committed Dec 13, 2024
1 parent 2719071 commit 22765d1
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 110 deletions.
22 changes: 22 additions & 0 deletions pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Pod
metadata:
name: httpbin-pod
namespace: mynamespacefdbf2b
labels:
app: httpbin
annotations:
azure.workload.identity/inject-proxy-sidecar: "true"
azure.workload.identity/proxy-sidecar-port: "8000"
spec:
serviceAccountName: myserviceaccountfdbf2b
containers:
- name: httpbin
image: docker.io/kennethreitz/httpbin
env:
- name: IDENTITY_ENDPOINT
value: "http://localhost:8000/metadata/identity/oauth2/token"
- name: IDENTITY_HEADER
value: "true"
- name: IMDS_ENDPOINT
value: "http://169.254.169.254"
91 changes: 91 additions & 0 deletions scenarios/SpringBoot/spring-boot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# SpringBootDemo
Spring Boot application that we will deploy to Kubernetes clusters in all 3 clouds

# Building and deploying the docker image:
```bash
sudo apt-get install -y default-jdk maven
```
```bash
mvn clean install
```
```bash
mvn spring-boot:run
```
```bash
docker build -t spring-boot-demo.jar .
docker run -p 9091:8080 spring-boot-demo.jar
```

# Deploying to VM

## Azure

### Create and connect to the VM
Set up parameter variables:

```bash
export SUBSCRIPTION=ad70ac39-7cb2-4ed2-8678-f192bc4272b6 # customize this
export RESOURCE_GROUP=SpringBoot # customize this
export REGION=westus2 # customize this
export VM_NAME=springboot-vm
export VM_IMAGE=UbuntuLTS
export ADMIN_USERNAME=vm-admin-name # customize this
```

Log in and create VM:

```bash
az group create --name ${RESOURCE_GROUP} --location ${REGION}
az vm create \
--resource-group ${RESOURCE_GROUP} \
--name ${VM_NAME} \
--image ${VM_IMAGE} \
--admin-username ${ADMIN_USERNAME} \
--generate-ssh-keys \
--public-ip-sku Standard --size standard_d4s_v3
```

Store the VM IP address for later:

```bash
VM_IP_ADDRESS=`az vm show -d -g ${RESOURCE_GROUP} -n ${VM_NAME} --query publicIps -o tsv`
```

Run the following to open port 8080 on the vm since SpringBoot uses it

```bash
az vm open-port --port 8080 --resource-group ${RESOURCE_GROUP} --name ${VM_NAME} --priority 1100
```

Connect to the VM:

```bash
ssh ${ADMIN_USERNAME}@${VM_IP_ADDRESS}
```

### Deploy the application

Install Java and maven needed for application

```bash
sudo apt update
sudo apt install default-jdk
sudo apt install maven
```

Now it's time to clone the project into the vm and give it proper permissions:

```bash
cd /opt
sudo git clone https://github.com/dasha91/SpringBootDemo
cd SpringBootDemo
sudo chmod -R 777 /opt/SpringBootDemo/
```

Run and deploy the app
```bash
mvn clean install
mvn spring-boot:run
```

Finally go to http://[$VM_IP_ADDRESS]:8080 to confirm that it's working :D :D :D
Loading

0 comments on commit 22765d1

Please sign in to comment.