Skip to content

fedor-malyshkin/k8s-coding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

k8s-coding

A k8s pet-project

Requirements

Steps

Install k3d (if hasn't done yet)

Install k3d

curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash

Create local docker registry

k3d registry create --port 0.0.0.0:5111

NOTE: Delete cluster

k3d registry delete k3d-registry

Create Kubernetes cluster

k3d cluster create k8scodingdemo  --registry-use k3d-registry:5111 -p 8080:80@loadbalancer

NOTE: Delete cluster

k3d cluster delete k8scodingdemo 

Check nodes:

kubectl get nodes

Install Kubernetes Dashboard

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

Create admin-user. Create a file admin-user.yml

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: admin-user
    namespace: kubernetes-dashboard

Apply config file by command kubectl apply -f admin-user.yml

Create a Bearer Tokens token:

kubectl -n kubernetes-dashboard create token admin-user

Start proxy:

kubectl proxy

Dashboard will be accessible as: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

Install RabbitMQ into Kubernetes

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install rabbitmq-broker --set auth.username=admin,auth.password=secretpassword bitnami/rabbitmq

RabbitMQ can be accessed within the cluster on port at rabbitmq-broker.default.svc

To access for outside the cluster, perform the following steps:

To Access the RabbitMQ AMQP port:

echo "URL : amqp://127.0.0.1:5672/"
kubectl port-forward --namespace default svc/rabbitmq-broker 5672:5672

To Access the RabbitMQ Management interface:

echo "URL : http://127.0.0.1:15672/"
kubectl port-forward --namespace default svc/rabbitmq-broker 15672:15672

Deploy apps into Kubernetes

Look at call-collector's README

Configure Ingress in Kubernetes

k3d/k3s already have https://traefik.io/ as ingress implementation.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: echoserver
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
    - http:
        paths:
          - path: /answer
            pathType: Prefix
            backend:
              service:
                name: q-c-call-collector
                port:
                  number: 8080          
          - path: /call
            pathType: Prefix
            backend:
              service:
                name: q-c-call-collector
                port:
                  number: 8080
          - path: /ask
            pathType: Prefix
            backend:
              service:
                name: q-c-call-collector
                port:
                  number: 8080

Play!

Try that it works:

curl localhost:9080/ask

Try to send a message

curl -v POST localhost:9080/call -d "some body content"

Check the set of received messages

curl http://localhost:9080/answer/snapshot

Check the set of received messages as a stream

curl http://localhost:9080/answer/stream