"New Epics". Peb noj ntxhw hauv qhov chaw

"New Epics". Peb noj ntxhw hauv qhov chaw

Hauv tsab xov xwm no, kuv yuav teeb tsa qhov chaw ua haujlwm rau kev tsim qhov kev ua si "Epics", thiab tseem yuav rhuav tshem qhov kev ua si nws tus kheej rau hauv qhov chaw tsim nyog siv hauv OpenFaaS. Kuv yuav ua txhua yam kev tswj hwm ntawm Linux, Kuv yuav xa Kubernetes hauv minikube siv VirtualBox. Kuv lub tshuab ua haujlwm muaj 2 processor cores thiab 12GB ntawm RAM; Kuv siv SSD ua qhov system disk. Kuv yuav siv debian 8 raws li kuv qhov kev txhim kho tseem ceeb, nrog emacs, sudo, git thiab virtualbox pob teeb tsa, txhua yam yuav raug teeb tsa los ntawm rub tawm los ntawm GitHub thiab lwm qhov chaw. Peb yuav nruab cov ntawv thov no hauv /usr/local/bin tshwj tsis yog tau teev tseg. Cia peb pib!

Npaj qhov chaw ua haujlwm

Txhim kho Go

Peb ua raws li cov lus qhia los ntawm lub vev xaib official:

$ curl -L0 https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz -o go.tar.gz
$ sudo tar -C /usr/local -xzf go.tar.gz
$ echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile

Tshawb xyuas kev ua haujlwm:

$ mkdir -p ~/go/src/hello && cd ~/go/src/hello
$ echo 'package main

import "fmt"

func main() {
fmt.Printf("hello, worldn")
}' > hello.go
$ go build
$ ./hello
hello, world

Txhim kho faas-cli

Peb ua raws li cov lus qhia los ntawm lub vev xaib official:

$ curl -sSL https://cli.openfaas.com | sudo -E sh
x86_64
Downloading package https://github.com/openfaas/faas-cli/releases/download/0.11.3/faas-cli as /tmp/faas-cli
Download complete.

Running with sufficient permissions to attempt to move faas-cli to /usr/local/bin
New version of faas-cli installed to /usr/local/bin
Creating alias 'faas' for 'faas-cli'.
  ___                   _____           ____
 / _  _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_  / _  '_ | |_ / _` |/ _` ___ 
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 ___/| .__/ ___|_| |_|_|  __,_|__,_|____/
      |_|

CLI:
 commit:  73004c23e5a4d3fdb7352f953247473477477a64
 version: 0.11.3

Tsis tas li ntawd, koj tuaj yeem pab ua kom tiav bash:

faas-cli completion --shell bash | sudo tee /etc/bash_completion.d/faas-cli

Txhim kho thiab Configuring Kubernetes

Rau kev txhim kho, minikube txaus, yog li nruab nws thiab kubelet hauv / usr / local / bin, thiab nruab lub kaus mom rau nruab daim ntawv thov:

$ curl https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -o minikube && chmod +x minikube && sudo mv minikube /usr/local/bin/
$ curl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -o kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
$ curl https://get.helm.sh/helm-v3.0.2-linux-amd64.tar.gz | tar -xzvf - linux-amd64/helm --strip-components=1; sudo mv helm /usr/local/bin

Launch minikube:

$ minikube start
  minikube v1.6.2 on Debian 8.11
  Automatically selected the 'virtualbox' driver (alternates: [])
  Downloading VM boot image ...
    > minikube-v1.6.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s
    > minikube-v1.6.0.iso: 150.93 MiB / 150.93 MiB [-] 100.00% 5.67 MiB p/s 27s
  Creating virtualbox VM (CPUs=2, Memory=8192MB, Disk=20000MB) ...
  Preparing Kubernetes v1.17.0 on Docker '19.03.5' ...
  Downloading kubeadm v1.17.0
  Downloading kubelet v1.17.0
  Pulling images ...
  Launching Kubernetes ...  Waiting for cluster to come online ...
  Done! kubectl is now configured to use "minikube"

Peb tshawb xyuas:

$ kubectl get pods --all-namespaces
NAMESPACE     NAME                               READY   STATUS    RESTARTS   AGE
kube-system   coredns-6955765f44-knlcb           1/1     Running   0          29m
kube-system   coredns-6955765f44-t9cpn           1/1     Running   0          29m
kube-system   etcd-minikube                      1/1     Running   0          28m
kube-system   kube-addon-manager-minikube        1/1     Running   0          28m
kube-system   kube-apiserver-minikube            1/1     Running   0          28m
kube-system   kube-controller-manager-minikube   1/1     Running   0          28m
kube-system   kube-proxy-hv2wc                   1/1     Running   0          29m
kube-system   kube-scheduler-minikube            1/1     Running   0          28m
kube-system   storage-provisioner                1/1     Running   1          29m

Txhim kho OpenFaaS

Cov neeg tsim khoom pom zoo kom tsim 2 lub npe chaw ua haujlwm nrog:

$ kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
namespace/openfaas created
namespace/openfaas-fn created

Ntxiv ib lub repository rau helm:

$ helm repo add openfaas https://openfaas.github.io/faas-netes/
"openfaas" has been added to your repositories

Daim ntawv qhia muaj peev xwm los teeb tsa tus password ua ntej kev teeb tsa, cia peb siv nws thiab khaws cov ntaub ntawv nkag mus ua k8s zais cia:

$ PASSWORD=verysecurerandompasswordstring
$ kubectl -n openfaas create secret generic basic-auth --from-literal=basic-auth-user=admin --from-literal=basic-auth-password="$PASSWORD"
secret/basic-auth created

Cia peb siv:

$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "openfaas" chart repository
Update Complete.  Happy Helming!
$ helm upgrade openfaas --install openfaas/openfaas --namespace openfaas --set functionNamespace=openfaas-fn --set generateBasicAuth=false
Release "openfaas" does not exist. Installing it now.
NAME: openfaas
LAST DEPLOYED: Fri Dec 25 10:28:22 2019
NAMESPACE: openfaas
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
To verify that openfaas has started, run:

  kubectl -n openfaas get deployments -l "release=openfaas, app=openfaas"

Tom qab qee lub sij hawm, peb khiav cov lus txib:

$ kubectl -n openfaas get deployments -l "release=openfaas, app=openfaas"
NAME                READY   UP-TO-DATE   AVAILABLE   AGE
alertmanager        1/1     1            1           114s
basic-auth-plugin   1/1     1            1           114s
faas-idler          1/1     1            1           114s
gateway             1/1     1            1           114s
nats                1/1     1            1           114s
prometheus          1/1     1            1           114s
queue-worker        1/1     1            1           114s

Tshawb xyuas kev ua haujlwm:

$ kubectl rollout status -n openfaas deploy/gateway
deployment "gateway" successfully rolled out
$ kubectl port-forward -n openfaas svc/gateway 8080:8080 &
[1] 6985
Forwarding from 127.0.0.1:8080 -> 8080
$ echo -n $PASSWORD | faas-cli login --username admin --password-stdin
Calling the OpenFaaS server to validate the credentials...
Handling connection for 8080
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
credentials saved for admin http://127.0.0.1:8080
$ faas-cli list
Function                        Invocations     Replicas

Txhim kho Mongodb

Peb nruab txhua yam siv lub kaus mom hlau:

$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories
$ helm install stable/mongodb --generate-name
NAME: mongodb-1577466908
LAST DEPLOYED: Fri Dec 25 11:15:11 2019
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **

MongoDB can be accessed via port 27017 on the following DNS name from within your cluster:

    mongodb-1577466908.default.svc.cluster.local

To get the root password run:

    export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace default mongodb-1577466908 -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)

To connect to your database run the following command:

    kubectl run --namespace default mongodb-1577466908-client --rm --tty -i --restart='Never' --image bitnami/mongodb --command -- mongo admin --host mongodb-1577466908 --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace default svc/mongodb-1577466908 27017:27017 &
    mongo --host 127.0.0.1 --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD

Peb tshawb xyuas:

kubectl run --namespace default mongodb-1577466908-client --rm --tty -i --restart='Never' --image bitnami/mongodb --command -- mongo admin --host mongodb-1577466908 --authenticationDatabase admin -u root -p $(kubectl get secret --namespace default mongodb-1577466908 -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)
If you don't see a command prompt, try pressing enter.

> db.version();
4.0.14

Nias ctrl + D kom tawm hauv lub thawv.

Kev teeb tsa emacs

Nyob rau hauv txoj cai, txhua yam twb configured raws li qhov no tsab xov xwm, yog li kuv yuav tsis mus rau hauv kev nthuav dav.

rhuav tshem qhov kev ua si rau hauv kev ua haujlwm

Kev cuam tshuam nrog kev ua haujlwm yog ua los ntawm http raws tu qauv, qhov kawg-rau-kawg authentication ntawm cov haujlwm sib txawv yog muab los ntawm JWT. Mongodb yog siv los khaws cov tokens, nrog rau kev ua si hauv xeev, cov ntaub ntawv neeg ua si, cov kab ke ntawm txhua qhov kev ua si thiab lwm yam ntaub ntawv. Cia peb saib ze ntawm cov yam ntxwv nthuav dav tshaj plaws.

sau npe

Lub tswv yim ntawm qhov kev ua haujlwm no yog JSON nrog lub npe menyuam yaus thiab tus password game. Thaum lub luag haujlwm no hu ua, nws raug kuaj xyuas tias qhov alias no tsis nyob hauv cov ntaub ntawv; yog tias daim tshev ua tiav, lub alias thiab lo lus zais hash tau muab tso rau hauv cov ntaub ntawv. Kev tso npe yuav tsum tau koom nrog hauv qhov kev ua si.

nkag

Cov tswv yim muaj nuj nqi yog JSON nrog lub npe menyuam yaus thiab tus password; yog tias muaj lub npe menyuam yaus hauv cov ntaub ntawv thiab tus password tau ua tiav nrog cov ntawv khaws tseg yav dhau los, JWT raug xa rov qab, uas yuav tsum tau dhau mus rau lwm yam haujlwm thaum lawv nyob. hu ua. Ntau cov ntaub ntawv kev pabcuam tseem raug tso rau hauv cov ntaub ntawv, piv txwv li, lub sijhawm nkag mus dhau los, thiab lwm yam.

Saib cov npe ua si

Txhua tus neeg siv tsis tau tso cai tuaj yeem thov cov npe ntawm txhua qhov kev ua si tshwj tsis yog cov nquag siv. Tus neeg siv tau tso cai kuj pom cov npe ntawm cov kev ua si nquag. Qhov tshwm sim ntawm kev ua haujlwm yog JSON uas muaj cov npe ntawm cov kev ua si (game ID, tib neeg nyeem lub npe, thiab lwm yam).

Kev ua si tsim

Qhov kev ua haujlwm tsuas yog ua haujlwm nrog cov neeg siv tau tso cai; qhov siab tshaj plaws ntawm cov players raug lees txais ntawm cov tswv yim, nrog rau cov kev ua si tsis zoo (piv txwv li, cov cim twg los qhib rau hauv qhov kev ua si, cov neeg ua si ntau tshaj plaws, thiab lwm yam). Ib qho kev sib cais ntawm qhov kev ua si yog qhov muaj tus password rau kev koom nrog, uas tso cai rau koj los tsim cov kev ua si uas tsis yog pej xeem. Los ntawm lub neej ntawd, kev ua si pej xeem raug tsim. Qhov tshwm sim ntawm kev ua haujlwm yog JSON, uas muaj qhov chaw ua tiav kev tsim, tus cim kev ua si tshwj xeeb, thiab lwm yam tsis muaj.

Koom nrog qhov kev ua si

Kev ua haujlwm tsuas yog ua haujlwm nrog cov neeg siv tau tso cai, cov tswv yim yog tus ID game thiab nws lo lus zais, yog tias qhov no tsis yog pej xeem kev ua si, qhov tso tawm yog JSON nrog cov kev ua si tsis. Cov neeg siv tau tso cai uas tau koom nrog qhov kev ua si, nrog rau tus tsim ntawm qhov kev ua si, yog nyob ntawm no hu ua cov neeg koom ua si.

Saib cov xwm txheej ua si

Txhua tus neeg siv tsis tau tso cai tuaj yeem thov cov npe ntawm cov xwm txheej rau kev ua si tsis ua haujlwm, thiab tus neeg siv tau tso cai tuaj yeem tau txais cov npe ntawm cov xwm txheej rau txhua qhov kev ua si nquag. Ib qho ntxiv rau qhov ua haujlwm tuaj yeem yog tus lej tshwm sim uas tus neeg siv twb muaj lawm. Hauv qhov no, tsuas yog cov xwm txheej tshwm sim tom qab ntawd yuav raug xa rov qab rau hauv daim ntawv teev npe. Los ntawm kev pib ua haujlwm no ib ntus, tus neeg siv tau tso cai saib dab tsi tshwm sim hauv qhov kev ua si. Qhov kev ua haujlwm no tseem xa rov qab qhov kev thov ua haujlwm, uas tus neeg siv tuaj yeem teb rau kev siv qhov kev ua si qhov kev tshwm sim xa tawm.

Xa ib qho kev ua si

Lub luag haujlwm ua haujlwm tsuas yog rau cov neeg koom nrog kev ua si: nws tuaj yeem pib qhov kev ua si, txav mus los, pov npav, sau cov ntawv uas tau tshwm sim hauv cov npe ntawm cov xwm txheej game, thiab lwm yam.
Tus neeg siv tau tso cai uas tsim qhov kev ua si pib faib cov luag haujlwm rau txhua tus neeg koom hauv kev ua si, suav nrog lawv tus kheej, lawv yuav tsum paub meej tias lawv lub luag haujlwm siv tib lub luag haujlwm. Thaum txhua lub luag haujlwm raug lees paub, qhov kev ua si cia li hloov mus rau hmo ntuj.

Kev ua si txheeb cais

Lub luag haujlwm ua haujlwm tsuas yog rau cov neeg koom nrog kev ua si; ​​nws qhia txog lub xeev ntawm qhov kev ua si, cov npe thiab cov naj npawb ntawm cov players (nicknames), lub luag haujlwm thiab lawv cov xwm txheej (tshem tawm lossis tsis ua), nrog rau lwm cov ntaub ntawv. Raws li nrog cov haujlwm dhau los, txhua yam ua haujlwm tsuas yog rau cov neeg koom nrog kev ua si.

Lub sijhawm pib ua haujlwm

Yog tias qhov kev ua si tsis tau raug tso tawm rau qee lub sijhawm tau teev tseg thaum tsim qhov kev ua si, nws yuav raug tshem tawm ntawm cov npe ntawm cov kev ua si nquag siv cov haujlwm meej.

Lwm lub sijhawm ua haujlwm yog qhov yuam kev hloov ntawm hom kev ua si los ntawm hmo ntuj mus rau hnub thiab rov qab rau kev ua si uas qhov no tsis tshwm sim thaum lub sijhawm tig (piv txwv li, tus neeg ua si uas yuav tsum tau hnov ​​​​mob rau qhov kev tshwm sim game tsis xa nws cov kev daws teeb meem rau qee qhov laj thawj. ).

Tshaj tawm

  • Taw qhia
  • Kev teeb tsa ib puag ncig kev txhim kho, rhuav tshem cov haujlwm ua haujlwm
  • Backend ua haujlwm
  • Frontend ua haujlwm
  • Teeb tsa CICD, teeb tsa kev sim
  • Pib lub rooj sib tham sim ua si
  • Cov txiaj ntsim tau los

Tau qhov twg los: www.hab.com

Ntxiv ib saib