Skip to content

Latest commit

 

History

History
140 lines (98 loc) · 2.35 KB

3.microservice.md

File metadata and controls

140 lines (98 loc) · 2.35 KB

Understand Microservice

Microservice demo, run nginx as webserver

$ kubectl run --image=nginx nginx

Show running pod

$ kubectl get po --show-labels -owide -w

Expose svc

$ kubectl expose deploy nginx --selector run=nginx --port=80 --type=NodePort

Check svc detail

$ kubectl get svc

Check nodeip

$ minikube ssh
$ ifconfig eth1

Access service

$ curl <nodeip>:<nodeport>

Run envoy

$ kubectl create configmap envoy-config --from-file=envoy.yaml
$ kubectl create -f envoy-deploy.yaml
$ kubectl expose deploy envoy --selector run=envoy --port=10000 --type=NodePort

Access service

$ curl <nodeip>:<nodeport>

Scale up/down/failover

$ kubectl scale deploy <deployment-name> --replicas=<n>

ConfigMap

cat game.properties

#configmap from file
kubectl create configmap game-config --from-file=game.properties
kubectl create configmap game-env-config --from-env-file=game.properties
kubectl get configmap -oyaml game-config

ConfigMap from literal

kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
#downward api pod
kubectl create -f downward-api-pod.yaml
kubectl get po downward-api-pod
kubectl logs -f downward-api-pod

Volume

kubectl create -f configmap-volume-pod.yaml
kubectl get po
kubectl logs -f configmap-volume-pod

Readiness probe

kubectl create -f centos-readiness.yaml

Multiple container pods

Get object by columns

kubectl get svc  -o=custom-columns=NAME:.metadata.name,CREATED:'.metadata.annotations'

Operator

kubebuilder

$ kubebuilder init --domain example.com
$ kubebuilder create api --group infra --version v1 --kind WebService
$ make install

Operator sdk

Create new project

operator-sdk new memorycache-operator

Add types

cd memorycache-operator
operator-sdk add api --api-version=cache.example.com/v1alpha1 --kind=Memcached

Modify types and generate new code

operator-sdk generate k8s
operator-sdk generate openapi

Operator helm

operator-sdk new nginx-operator --type=helm --kind=Nginx --api-version=web.example.com/v1alpha1
operator-sdk add crd --api-version=web.example.com/v1alpha1 --kind=Envoy --update-watches=true