Build localstack on local k8s cluster - updated

Localstack on local k8s cluster - updated

Installation with yaml file

  1. Set up your Kubernetes cluster:

    • Install a Kubernetes cluster locally. Follow the respective documentation for installation instructions.
  2. Deploy localStack and localstack web dashboard to your Kubernetes cluster:

    • Create a Kubernetes deployment YAML file, for example, localstack-deployment.yaml with the following contents:

      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
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      100
      101
      102
      103
      104
      105
      apiVersion: v1
      kind: Namespace
      metadata:
      name: localstack

      ---

      apiVersion: apps/v1
      kind: Deployment
      metadata:
      name: localstack
      namespace: localstack
      spec:
      replicas: 1
      selector:
      matchLabels:
      app: localstack
      template:
      metadata:
      labels:
      app: localstack
      spec:
      containers:
      - name: localstack
      image: localstack/localstack
      ports:
      - containerPort: 4566
      env:
      - name: SERVICES
      value: "*"
      resources:
      limits:
      cpu: 1
      memory: 1Gi
      requests:
      cpu: 500m
      memory: 500Mi

      ---

      apiVersion: v1
      kind: Service
      metadata:
      name: localstack
      namespace: localstack
      spec:
      selector:
      app: localstack
      ports:
      - name: localstack-port
      protocol: TCP
      port: 4566
      targetPort: 4566
      type: NodePort

      ---

      apiVersion: apps/v1
      kind: Deployment
      metadata:
      name: localstack-web
      namespace: localstack
      spec:
      replicas: 1
      selector:
      matchLabels:
      app: localstack-web
      template:
      metadata:
      labels:
      app: localstack-web
      spec:
      containers:
      - name: localstack-web
      image: localstack/localstack-web
      ports:
      - containerPort: 8080
      env:
      - name: SERVICES
      value: "*"
      resources:
      limits:
      cpu: 500m
      memory: 500Mi
      requests:
      cpu: 250m
      memory: 250Mi

      ---

      apiVersion: v1
      kind: Service
      metadata:
      name: localstack-web
      namespace: localstack
      spec:
      selector:
      app: localstack-web
      ports:
      - name: localstack-web-port
      protocol: TCP
      port: 8080
      targetPort: 8080
      type: NodePort

    • Apply the deployment to your Kubernetes cluster: kubectl apply -f localstack-deployment.yaml.

  3. Access LocalStack services:

    With the LocalStack deployment described in the localstack-deployment.yaml file, you can determine the AWS endpoints for each service by using the following steps:

    1. Find the NodePort assigned to the localstack service:

      • Run the following command to get the NodePort value:

        1
        kubectl get service -n localstack localstack -o jsonpath='{.spec.ports[0].nodePort}'
      • Note down the NodePort value returned by the command.

    2. Determine the IP address of your Kubernetes cluster:

      • Run the following command to get the IP address of your cluster:

        1
        kubectl cluster-info | grep 'Kubernetes master' | awk '/http/ {print $NF}' | sed -e 's/.*\/\///'
      • Note down the IP address returned by the command.

    3. Build the AWS service endpoint URLs:

      • Combine the IP address and NodePort value obtained in the previous steps to construct the AWS service endpoints:

        • For LocalStack services, the endpoint URL format is:

          1
          http://<Cluster-IP>:<NodePort>

          Replace <Cluster-IP> with the IP address of your Kubernetes cluster, and <NodePort> with the NodePort value from step 1.

        • For each AWS service, the endpoint URL format is:

          1
          http://<Cluster-IP>:<NodePort>/<Service-Name>

          Replace <Cluster-IP> with the IP address of your Kubernetes cluster, <NodePort> with the NodePort value from step 1, and <Service-Name> with the name of the AWS service (e.g., s3, sqs, lambda).

    For example, if your cluster’s IP address is 192.168.1.100 and the NodePort assigned to the localstack service is 30000, here are a few examples of AWS service endpoint URLs:

    • S3: http://192.168.1.100:30000/s3
    • SQS: http://192.168.1.100:30000/sqs
    • Lambda: http://192.168.1.100:30000/lambda

Installation with helm3

Follow the guide here: https://docs.localstack.cloud/getting-started/installation/

1
helm repo add localstack-repo https://helm.localstack.cloud
1
2
3
4
5
6
7
8
9
10
11
12
[root@CentOS001 ~]# helm upgrade --install localstack localstack-repo/localstack
Release "localstack" does not exist. Installing it now.
NAME: localstack
LAST DEPLOYED: Mon Dec 11 03:57:02 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace "default" -o jsonpath="{.spec.ports[0].nodePort}" services localstack)
export NODE_IP=$(kubectl get nodes --namespace "default" -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT

Build localstack on local k8s cluster - updated
https://blog.excelsre.com/2023/12/10/build-localstack-on-local-k8s-cluster-updated/
作者
Felix Yang
发布于
2023年12月10日
许可协议