Sign inSign up

lmldocker/web-socket-activation

By lmldocker

•Updated almost 4 years ago

Testing - http acho

Image
0

147

lmldocker/web-socket-activation repository overview

⁠lmldocker/web-socket-activation:2.0

⁠DOCKER

docker run  \
--publish 1085:1085  \
--name web-socket-activation-container  \
--env WEB_SOCKET_ACTIVATION_PORT=1085   \
--env WEB_SOCKET_ACTIVATION_ID=NODE-1085  \
--restart=always \
--detach \
--memory 600m \
--cpus 1 \
lmldocker/web-socket-activation:2.0

//  --env WEB_SOCKET_ACTIVATION_LOG=/log/  \  let's keep it null then the log goes to standard-output
//  --volume /volume1:/log \

⁠KUBERNETES MANIFEST

⁠POD

Simple pod

apiVersion: v1
kind: Pod
metadata:
  name: web-socket-activation-pod
  labels:
    name: web-socket-activation-pod
spec:
  containers:
  - name: web-socket-activation-pod
    image: lmldocker/web-socket-activation:2.0
    resources:
      limits:
        memory: "500Mi"
        cpu: "1"
    ports:
      - containerPort: 300
    env:
    - name: WEB_SOCKET_ACTIVATION_PORT
      value: "300"
    - name: WEB_SOCKET_ACTIVATION_ID
      value: "web-socket-activation-pod-id-300"


//  kubectl apply -f web-socket-activation-pod.yaml

⁠POD on HOST-PORT
apiVersion: v1
kind: Pod
metadata:
  name: web-socket-activation-pod-hostport
  labels:
    name: web-socket-activation-pod-hostport
spec:
  containers:
  - name: web-socket-activation-pod-hostport
    image: lmldocker/web-socket-activation:2.0
    resources:
      limits:
        memory: "500Mi"
        cpu: "1"
    ports:
      - containerPort: 301
        hostPort: 301
    env:
    - name: WEB_SOCKET_ACTIVATION_PORT
      value: "301"
    - name: WEB_SOCKET_ACTIVATION_ID
      value: "web-socket-activation-pod-id-301"

kubectl apply -f web-socket-activation-pod-hostport.yaml

then test it .

curl -v 10.244.1.6:301 (or whatever is the IP of the container inside the node-cluster )

curl -v 127.0.0.1:301 (use loopback or the IP of the host-node-cluster )

Observation: if you are using KIND, then

get into the cluster-node using

docker exec -ti cluster-nodex-container-name /bin/bash

and execute the curl command inside it.

⁠DEPLOYMENT & SERVICE
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-socket-activation-deploy
  labels:
    app: websockactv
spec:
  replicas: 4    # Probably allocate 2 pods in each worker-node (1,2)
  selector:
    matchLabels:
      app: web-socket-activation-deploy
  template:
    metadata:
      labels:
        app: web-socket-activation-deploy
    spec:
      containers:
      - name: web-socket-activation-deploy-container
        image: lmldocker/web-socket-activation:2.0
        resources:
          limits:
            memory: "500Mi"
            cpu: "1"
        ports:
        - containerPort: 303
        env:
        - name: WEB_SOCKET_ACTIVATION_PORT
          value: "303"
        - name: WEB_SOCKET_ACTIVATION_ID
          value: "web-socket-activation-deploy-container-id-x"


---

apiVersion: v1
kind: Service
metadata:
  name: web-socket-activation-deploy-expose
spec:
  type: NodePort # ClusterIP (inside) |  LoadBalancer(outside) | NodePort(inside/eachNode33000+767) | ExternalName
  selector:
    app: web-socket-activation-deploy
  ports:
  - port: 303
    targetPort: 303



# kubectl apply -f web-socket-activation-deploy.yaml  --dry-run=client


# supported values: "ClusterIP", "ExternalName", "LoadBalancer", "NodePort"

# A Service can map any incoming port to a targetPort. By default and for convenience, 
#   the targetPort is set to the same value as the port field.

# ClusterIP: Exposes the Service on a cluster-internal IP. 
#            Choosing this value makes the Service only reachable from within the cluster. 
#             This is the default that is used if you don't explicitly specify a type for a Service.
# NodePort: Exposes the Service on each Node's IP at a static port (the NodePort). 
#           To make the node port available, Kubernetes sets up a cluster IP address, 
#           the same as if you had requested a Service of type: ClusterIP.
# LoadBalancer: Exposes the Service externally using a cloud provider's load balancer.
# ExternalName: Maps the Service to the contents of the externalName 
#               field (e.g. foo.bar.example.com), by returning a CNAME record with its value. 
#               No proxying of any kind is set up.


curl -v 10.96.189.92:303

Reached from

cluster-node-control-plane

cluster-node-worker-node1

cluster-node-worker-node2


⁠Access it from outside of the cluster

Let's route the request from outside to inside of the cluster.

kubectl port-forward svc/web-socket-activation-deploy-expose 1303:303

then simply access from another machine (using the IP address of the cluster) and port 1303 for example ( in this case )

On kind, just use the following command on bare session

curl http://127.0.0.1:1303⁠

Bytheway, to access from another machine using the ipaddress you're gonna need to expose on all ip address of the cluster-machine. use --address on the port-forward command

kubectl port-forward svc/web-socket-activation-deploy-expose --address 0.0.0.0 1303:303


by leonardo.labolida.com

Tag summary

Content type

Image

Digest

sha256:ea999bda0…

Size

87.5 MB

Last updated

almost 4 years ago

docker pull lmldocker/web-socket-activation:2.0