Redis HA on Kubernetes Cluster

Phachara A
2 min readJan 29, 2019

--

“It delivers sub-millisecond response times enabling millions of requests per second for real-time”

Redis HA on K8S

ลองมาใช้ Redis ช่วยในการจัดการ API ฝั่ง server กัน Redis คืออะไร? หาอ่านได้ครับ แต่เขา claim ว่ามันเร็วเพราะมันเป็น memory ใช้ systax แบบ no sql มันอ่านง่าย เขียนง่าย ใช้ง่าย To Doing

ติดตั้งด้วย Helm

Install Redis by Helm Status

Check.go {Code Function check}

func (a *App) checkEmail(w http.ResponseWriter, r *http.Request) { // API checkemailvar email *model.Kmos_Emailvar res Responddecoder := json.NewDecoder(r.Body)decoder.Decode(&email)defer r.Body.Close()var err errorif checkRedisConnection != false {_, err = api.RedisGetEmail(email.Email, a.Redis)}if err != nil || checkRedisConnection == false {res.Recieve_time = time.Now().Format("02-01-2006 15:04:05")e, err := api.CheckEmail(email.Email, a.DB)if err != nil {res.Message = "email not found"respondWithError(w, http.StatusOK, res)return}

ในส่วน describe ของ service ที่ deploy แบบ Automate ได้หน้าตาดังนี้

Name:                     kmos-api-uaa
Namespace: gitlab-demo
Labels:
Annotations: kubectl.kubernetes.io/last-applied-configuration= ---
Selector: app=kmos-api-uaa
Type: NodePort
IP: 10.100.17.102
Port: 80/TCP
TargetPort: kmos-api-uaa/TCP
NodePort: 31459/TCP
Endpoints: ---
Session Affinity: None
External Traffic Policy: Cluster
Events:

ไปดูใน Log ของ service จะเห็นว่า connect กับ Redis ได้แล้วพร้อม !!

ลอง Test ดูผลลัพท์จะเห็นว่า Response กับมา 0.3 sec เพราะเรา cache เก็บไว้เพื่อใช้ในการ return values จะแบ่งเบาภาระ Transection Database

redis-server cache KEYS values

conclusion

Redis คือสิ่งที่น่าสนใจและควรจะมีอย่างมากใน backend developer เป็น no-sql ที่ประมาลผลได้รวดเร็ว มากกว่า SSD ในการ cache รับส่งข้อมูล(แต่ต้องรู้จักว่าจะ cache ส่วนไหนอย่างไรบ้าง) และอีกทั้งเป็น open source ให้นำไปใช้ได้อย่างง่ายอีกด้วย

→ Message Broker |AWS Simple Queue Service | Redis | RabbitMQ |

# Next Choreography

#elon musk #tom hardy #freddie mercury #joseph stalin #ชัชชาติสิทธิพันธุ์

We just get ready !

Photo by takahiro taguchi on Unsplash

--

--

Phachara A
Phachara A

Written by Phachara A

Software Engineer /Architect Specialist DevOps Engineer /Cloud Architect/Folk

No responses yet