What we can learn from this post?

Install the Helm and use it to deploy the LocalStack into k8s

The LocalStack is a fully functional local cloud stack, which we can use to develop and
test the serverless apps offline.
We can use Helm to deploy the LocalStack into k8s

1
2
3
sudo snap install helm --classic
helm repo add localstack-repo https://localstack.github.io/helm-charts
helm upgrade --install localstack localstack-repo/localstack

To get the services host

1
2
3
export EDGE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services localstack)
export LOCALSTACK_HOST=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$LOCALSTACK_HOST:$EDGE_PORT

The output is similar to:

1
http://192.168.49.2:31566

Add persistent volume for the localstack

Deploy one volume into the cluster by using follows configures

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
apiVersion: v1
kind: PersistentVolume
metadata:
name: localstack-pv
labels:
type: local
spec:
storageClassName: standard
capacity:
storage: 50Gi
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
hostPath:
path: /data/localstack
type: DirectoryOrCreate

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: localstack-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
volumeName: localstack-pv

Redeploy the LocalStack to load the volume. For more parameters please
refer document

1
helm upgrade localstack localstack-repo/localstack --set-string persistence.enabled=true,persistence.size=50Gi,ingress.enabled=true,persistence.storageClass=standard,persistence.existingClaim=localstack-pvc

Testing the S3 service from LocalStack

1
2
3
4
5
pip install awscli-local

# Special environments for the aws-local
export LOCALSTACK_HOST=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
export EDGE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services localstack)
1
2
3
awslocal s3 mb s3://test-bucket
# The output should be:
>> make_bucket: test-bucket
1
awslocal s3 sync ./public s3://test-bucket
1
2
3
4
5
6
7
8
9
10
11
12
awslocal s3 ls s3://test-bucket

# The output will be:
PRE 2022/
PRE archives/
PRE css/
PRE img/
PRE js/
PRE libs/
PRE tags/
2022-04-21 10:20:02 766 favicon.ico
2022-04-21 10:20:02 4650 index.html
1
awslocal s3 cp s3://test-bucket/index.html /tmp/index.html
1
awslocal s3 rm s3://test-bucket/index.html
1
2
3
4
{
endpoint: 'http://minikube:31566',
use_path_style_endpoint: true
}