Posts

Showing posts from 2022

Redis pubsub and reactive programming

 https://github.com/jonashackt/spring-reactive-redis-messaging

Assign pods to nodes

 https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/

How to understand Prometheus query

http_requests_total{environment="testing",method="GET"} = 1 http_requests_total{environment="development",method="GET"} = 2 http_requests_total{environment="staging",method="GET"} = 1 Nếu bạn muốn hiển thị 1 metric lĂ  tổng số request GET thì chỉ cần đơn giản thá»±c hiện query sau sum (http_requests_total{method="GET"}) sum (http_requests_total{method="GET"}) without(environment) sum (http_requests_total{method="GET"}) by(method)

Check logs in docker container

watch -n 0 "docker logs mycontainer"

Check worker node usage

  Use the following commands to check workload usage in CLI: kubectl top pod kubectl describe pod NAME                             CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%     node-1   185m         11%     2671Mi           39%         node-2   145m         9%     2755Mi           40%         node-3   177m         11%     2767Mi           40%         coax-1         1137m         31%     3132Mi           45%         coax-2         107m         2%     1969Mi           28%     ...

Service account token

1. => tạo service account kubectl create serviceaccount deployer 2. => tạo binding giữa service accounts vĂ  role-admin kubectl create clusterrolebinding deployer-binding --clusterrole=cluster-admin \ --serviceaccount= default :deployer 3. => Tạo token vá»›i name deployer-secret vĂ  attach vĂ o service account deployer kubectl apply -f - <<EOF apiVersion: v1 kind: Secret metadata: name: deployer-secret annotations: kubernetes.io/service-account.name: deployer type: kubernetes.io/ service-account-token EOF 4. => hiển thị danh sĂ¡ch tĂªn cĂ¡c token Ä‘Ă£ được tạo ra kubectl get secrets 5. => view token value cho deployer Ä‘Ă£ tạo kubectl describe secret deployer-token-nmx8l https: //cloudhedge.io/setting-up-kubernetes-api-access-using-service-account/

Emit Events with sink

  private final Sinks.Many<String> eventSink = Sinks. many ().multicast().directBestEffort() ; @GetMapping (value = "/{id}" , produces = MediaType. TEXT_EVENT_STREAM_VALUE ) public Flux<ServerSentEvent<String>> sse ( @PathVariable ( "id" ) String id) { final AtomicLong counter = new AtomicLong( 0 ) ; return eventSink .asFlux() .filter(e -> e.equals( id )) .map(e -> { System. out .println(Thread. currentThread ().getName()) ; return ServerSentEvent. builder (e) .id( counter .incrementAndGet() + "" ) .event(e.toLowerCase() + "-" + new SimpleDateFormat( "yyyy.MM.dd.HH.mm.ss" ).format( new java.util.Date())) .build() ; }) ; } @ResponseStatus (HttpStatus. OK ) @ResponseBody ...

Add public key to ssh-open server to login without password

https://linuxhint.com/ssh-using-private-key-linux/  On the remote server we need to chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys

Creat ssh server within container docker

 https://dev.to/s1ntaxe770r/how-to-setup-ssh-within-a-docker-container-i5i

If else in helmchart

apiVersion : {{ .Values.env.INGRESS_API_VERSION }} kind : Ingress metadata : name : service-name annotations : kubernetes.io/ingress.class : nginx spec : rules : - host : {{ .Values.ingress.host | quote }} http : paths : {{- if eq .Values.env.INGRESS_API_VERSION "networking.k8s.io/v1" }} - path : "/" backend : service : name : service-name port : number : 80 pathType : Prefix {{- else if eq .Values.env.INGRESS_API_VERSION "extensions/v1beta1" }} - path : "/" backend : serviceName : service-name servicePort : http {{- end }}  

Show helm chart template

helm install charts/service-name --dry-run --debug -f charts/service/values/prod/values.yaml --generate-name=true

Jenkins pipeline example

pipeline{ agent any environment { DOCKER_USER='robot_config' DOCKER_PASS='xxxxxxxx' DOCKER_REGISTRY='harbor.google.com' DOCKER_PROJECT='config-server-test' IMAGE_NAME='config-server' TAG='latest' SERVICE='config-server' ENV='beta' NAMESPACE='jenkins' SERVER_URL='https://vks-api/v1/k8s/97afc070-xxxx-4171-xxxx-yyyyy' SVC_TOKEN='yyyyyy' } stages{ stage('Checkout config-server git repository') { steps { git branch: 'feature/jenkins', credentialsId: 'git.x.com_credential_for_Github_Organization_pipeline', url: 'git@git.com:harmmy/cs.git' withCredentials([string(credentialsId: 'password', variable: 'SECRET')]) { //set SECRET with the credential conten...

Run a command in ansible

Run a cmd - name: Install gradle hosts: localhost connection: local tasks: - name: Unzip gradle ansible.builtin.command: unzip gradle-7.2-bin.zip register: myoutput - name: Create gradle folder ansible.builtin.command: mkdir gradle_temp register: myoutput - name: Move gralde file to folder ansible.builtin.command: mv gradle-7.2 ./gradle_temp/gralde register: myoutput Create folder in ansible - name: Create gradle folder file: path: /usr/local/gradle state: directory

Ansible- [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

 The solution is that you add your server address into the /etc/ansible/hosts 127.0.0.1 abc.com.vn

Logback -spring boot

  <? xml version ="1.0" encoding ="UTF-8" ?> <configuration> <include resource ="org/springframework/boot/logging/logback/defaults.xml" /> <appender name ="GENERAL" class ="ch.qos.logback.core.ConsoleAppender" > <encoder> <pattern> ${CONSOLE_LOG_PATTERN} </pattern> </encoder> </appender> <appender name ="LOG_INFO" class ="ch.qos.logback.core.rolling.RollingFileAppender" > <file> log/tfo-iims-INFO.log </file> <rollingPolicy class ="ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <!-- daily rollover --> <fileNamePattern> log/tfo-iims-INFO-%d{yyyy-MM-dd}.log </fileNamePattern> <maxHistory> 30 </maxHistory> </rollingPolicy> <filter class ="ch.qos.logback.classic.filter.LevelFilter" > <level> INFO </level>...

Docker compose demo

  --- version : "3.8" services : nodejs-app : build : ./frontend depends_on : - backend ports : - protocol : tcp published : 80 target : 8000 restart : always volumes : - /app/frontend:/app - /app/node_modules networks : - front-internal command : npm run start python-app : build : ./backend depends_on : - database restart : always ports : - protocol : udp published : 8001 target : 8001 mysql : image : mysql:5.7 ports : - 3306:3306 command : mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp volumes : - ./database:/var/lib/mysql environment : MYSQL_ROOT_PASSWORD : changeme MYSQL_ROOT_USER : changeme networks : front-internal : driver : bridge