Distributed Tracing FAQ
Posted by
Manish Panchmatia
on Thursday, November 14, 2019
Labels:
DevOps,
istio,
k8s,
microservice,
software
/
Comments: (0)
Full article...>>
** Is tracing only for request-response pair? How tracing happens for
indication where response is not expected.
Zipkin
This is: One-way RPC Tracing. One-way is the same as normal RPC
tracing, except there is no response anticipated.
In normal RPC tracing 4 annotations are used: “cs” “sr” (request) then
“ss” “cr” (response). In one-way tracing, the first two are used “cs” “sr” as
there is no response returned to the caller.
So, the client adds “cs” to a span and reports it to zipkin. Then, the
server adds “sr” to the same span and reports it. Neither side add
Span.timestamp or duration because neither side know both when the span started
and finished.
CS = Client Send
SR = Server Receive
SS = Server Sent
CR = Client Receive
They are annotations for spans in Zipkin format
Jaeger
For asynchronous messaging communications: “span.kind” tag values are:
Producer and Consumer
For synchronous RPC communications: “span.kind” tag values are: Client
and Server
The span.kind=server tag denotes an entry span, e.g. a span created in
the local code in response to an external request. Likewise, span.kind=client
denotes an exit span, e.g. a call made from the local code to another server.
** At ‘Istio service mesh’, does ‘Envoy sidecar proxy’ add ‘B3 headers’
for incoming message or outgoing message,
For incoming message.
** What if some of the microservices use Zipkin format and new
microservices use Jaeger format at K8s cluster?
Jaeger provides backward compatibility. So, just need to route ‘Zipkin
format data’ from ‘legacy services’ to ‘Jaeger backend’ using ‘zipkin
collector’
Backwards compatibility with Zipkin
Although we recommend instrumenting applications with OpenTracing API and
binding to Jaeger client libraries to benefit from advanced features not
available elsewhere, if your organization has already invested in the
instrumentation using Zipkin libraries, you do not have to rewrite all that
code. Jaeger provides backwards compatibility with Zipkin by accepting spans in
Zipkin formats (Thrift or JSON v1/v2) over HTTP. Switching from Zipkin backend
is just a matter of routing the traffic from Zipkin libraries to the Jaeger
backend.
** The ‘Envoy sidecar proxy’ at ‘Istio Service Mesh’ sends collected
span data (JSON format) to Jaeger Collector. It it for incoming message or
outgoing message?
The ‘Envoy sidecar proxy’ sends a single span (JSON format), asynchronously,
anytime, after receiving response for the request which was originated by
application.
** Can we bypass Jaeger Agent?
Yes for C++ Jaeger ClientLib.
** Can Jaeger Collector work on UDP?
No.
** How to use Baggage in Jaeger headers?
Key: uberctx-{baggage-key}
Value: url-encoded string
** How to use Baggage in Zipkin B3 header?
baggage-:
The support is only for Java and Go languages
** What is thrift
https://en.wikipedia.org/wiki/Apache_Thrift. It is for RPC with format
like: JSON, Binary etc.
** what is TChannel?
It is a protocol over TCP for RPC
** Does Zipkin supports binary/compress format?
Zipkin can work on TChannel. It also supports compact Thrift format.
However, Jaeger is better as being CNCF project.
** TChannel, Thrift, or its combination, which one is better?
Now, Jaeger collector supports gRPC as well. gRPC can be even better
choice.
** Wild card query is supported at Jaeger UI?
No, due to limitations of other storage implementations. However, one
can use Kibana + Elastic Search for the same.
Programming Kubernetes - I
Meetup Event : https://www.meetup.com/ kubernetes-openshift-India- Meetup/events/264123372/
* Only API server interact with etcd
* Extend K8s
1. Extend life cycle of API server by adding new controller
2. add more APIs : by adding new API resource types and by adding CRDs
3. cluster daemons for automation. E.g. collecting metrics
4. cluster assist to extend functionality. E.g. SSL certificate manager.
* Action or commands on K8s resources
1 create
2 read
- get
- list
- watch
3 update
- patch
- replace
4 delete
Here are all such actions/command on Deployment resource
https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/apps/v1/deployment.go
* API
apis/// namespace//resource
Short form : GVR = group, version, resource
Possible versions:
Alpha (v1alpha1)
Beta (v1beata1)
Stable (v1)
* Few useful commands
kubectl api version
kubectl api-resource
we can get short names
kubectl get --raw
* KIND used at YAML file is corrosponding to golang type. For any built-in K8s object:
1. https://github.com/kubernetes/api/blob/master///types.go has multiple struct in Go langugae corrpospond to each K8s object at YAML file.
2. https://github.com/kubernetes/client-go/tree/master/kubernetes/typed// folder has multiple files. Each file is corrsoponding to one K8s object.
* K8s support for client library implemented in many languages:
Official support for : Go, Python, Java, DotNet, JavaScript, Haskell
Many more language supported by community implementaiton
Please refer: https://kubernetes.io/docs/reference/using-api/client-libraries/ The source code is available at https://github.com/kubernetes-client
Out of all of them: client-go has cache and many more features. Kubectl and prometheus-operator also internally use client-go library. Important packages / utilities of client-go library are described at blog https://itnext.io/how-to- create-a-kubernetes-custom- controller-using-client-go- f36a7a7536cc E.g. Kubernetes, Discovery, Dynamic, Transport, Plugin, Scale, Util, tool/cache etc. tools/clientcmd package is useful to setup client from kubeconfig file.
* Flatcar Linux:
- an immutable Linux distribution for containers.
- a friendly fork of CoreOS’s Container Linux and as such, compatible with it.
- a self-updating operating system
- It is designed for containers, making it ideal for running Kubernetes and other container platforms.
- It aims to be an independently built, distributed, and supported Linux distribution designed for container workloads.
Reference : https://www.flatcar-linux.org/
* apimachienry
- Scheme, typing, encoding, decoding, and conversion packages for Kubernetes and Kubernetes-like API objects.
- This library is a shared dependency for servers and clients to work with Kubernetes API infrastructure without direct type dependencies.
- Its first consumers are k8s.io/kubernetes, k8s.io/client-go, and k8s.io/apiserver.
* "~/.kube/config" path has all the security related file to interface with K8s master node (or minikybe) kubeconfig has context
* controller uses service account. secreat is mounted inside pod
* jq is a lightweight and flexible command-line JSON processor. It is like sed for JSON. Reference : https://stedolan.github.io/jq/
* YAML file consists
1. api version
2. kind
3. matadata
4. spec
5. status
everything under metadata is in type of go language
Read Annotations
https://github.com/kubernetes/api/tree/master/core/v1
https://github.com/kubernetes/apimachinery/tree/master/pkg
Unit testing of controller with fake client
https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/client/fake/client_test.go
* Join K8s slack channel "k8sBLR"
Reference
Go Client to communicate with K8s cluster: https://github.com/kubernetes/client-go
Schema of the external API types that are served by the Kubernetes API server: https://github.com/kubernetes/api
All relevant blogs: https://kubernauts.dev/
PPT slide deck: https://docs.google.com/ presentation/d/ 1NgAxNrUxcOnodm9VA4plidrKradQM _kAbrTrF844gec/edit#slide=id. g5dcf860567_4_3
Github accounts
https://github.com/surajssd
https://github.com/surajssd/lspods
Relevant blogs
https://kubernetes.io/blog/2018/01/introducing-client-go-version-6/
https://itnext.io/how-to- create-a-kubernetes-custom- controller-using-client-go- f36a7a7536cc
https://medium.com/ speechmatics/how-to-write- kubernetes-custom-controllers- in-go-8014c4a04235
https://jvns.ca/blog/2017/06/04/learning-about-kubernetes/
Book
https://go.heptio.com/rs/383- ENX-437/images/Managing_ Kubernetes.pdf
https://www.oreilly.com/library/view/programming-kubernetes/9781492047094/
https://stackoverflow.com/questions/49953980/watch-customresourcedefinitions-crd-with-client-go
on 24th August 2019
* Extend K8s
1. Extend life cycle of API server by adding new controller
2. add more APIs : by adding new API resource types and by adding CRDs
3. cluster daemons for automation. E.g. collecting metrics
4. cluster assist to extend functionality. E.g. SSL certificate manager.
* Action or commands on K8s resources
1 create
2 read
- get
- list
- watch
3 update
- patch
- replace
4 delete
Here are all such actions/command on Deployment resource
https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/apps/v1/deployment.go
* API
apis/
Short form : GVR = group, version, resource
Possible versions:
Alpha (v1alpha1)
Beta (v1beata1)
Stable (v1)
* Few useful commands
kubectl api version
kubectl api-resource
we can get short names
kubectl get --raw
* KIND used at YAML file is corrosponding to golang type. For any built-in K8s object:
1. https://github.com/kubernetes/api/blob/master/
2. https://github.com/kubernetes/client-go/tree/master/kubernetes/typed/
* K8s support for client library implemented in many languages:
Official support for : Go, Python, Java, DotNet, JavaScript, Haskell
Many more language supported by community implementaiton
Please refer: https://kubernetes.io/docs/reference/using-api/client-libraries/ The source code is available at https://github.com/kubernetes-client
Out of all of them: client-go has cache and many more features. Kubectl and prometheus-operator also internally use client-go library. Important packages / utilities of client-go library are described at blog https://itnext.io/how-to-
* Flatcar Linux:
- an immutable Linux distribution for containers.
- a friendly fork of CoreOS’s Container Linux and as such, compatible with it.
- a self-updating operating system
- It is designed for containers, making it ideal for running Kubernetes and other container platforms.
- It aims to be an independently built, distributed, and supported Linux distribution designed for container workloads.
Reference : https://www.flatcar-linux.org/
* apimachienry
- Scheme, typing, encoding, decoding, and conversion packages for Kubernetes and Kubernetes-like API objects.
- This library is a shared dependency for servers and clients to work with Kubernetes API infrastructure without direct type dependencies.
- Its first consumers are k8s.io/kubernetes, k8s.io/client-go, and k8s.io/apiserver.
* "~/.kube/config" path has all the security related file to interface with K8s master node (or minikybe) kubeconfig has context
* controller uses service account. secreat is mounted inside pod
* jq is a lightweight and flexible command-line JSON processor. It is like sed for JSON. Reference : https://stedolan.github.io/jq/
* YAML file consists
1. api version
2. kind
3. matadata
4. spec
5. status
everything under metadata is in type of go language
Read Annotations
https://github.com/kubernetes/api/tree/master/core/v1
https://github.com/kubernetes/apimachinery/tree/master/pkg
Unit testing of controller with fake client
https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/client/fake/client_test.go
* Join K8s slack channel "k8sBLR"
Reference
Go Client to communicate with K8s cluster: https://github.com/kubernetes/client-go
Schema of the external API types that are served by the Kubernetes API server: https://github.com/kubernetes/api
All relevant blogs: https://kubernauts.dev/
PPT slide deck: https://docs.google.com/
Github accounts
https://github.com/surajssd
https://github.com/surajssd/lspods
Relevant blogs
https://kubernetes.io/blog/2018/01/introducing-client-go-version-6/
https://itnext.io/how-to-
https://medium.com/
https://jvns.ca/blog/2017/06/04/learning-about-kubernetes/
Book
https://go.heptio.com/rs/383-
https://www.oreilly.com/library/view/programming-kubernetes/9781492047094/
https://stackoverflow.com/questions/49953980/watch-customresourcedefinitions-crd-with-client-go
Alternatives of tcpdump
Posted by
Manish Panchmatia
on Friday, September 20, 2019
Labels:
DevOps,
k8s,
security,
software,
Telecom Wireless
/
Comments: (0)
Full article...>>
There
are many tools similar to tcpdump, as per https://en.wikipedia.org/wiki/Comparison_of_packet_analyzers
Here, I choose only Free and Open Source tools, whose docker
image is available and tool is lightweight.
- Ngrep
is best, for capture only those packets, whose payload has certain
pattern.
- Packetbeat is
lightweight open source packet analyzer. It sends data to Elastic Search
OR Logstash. It is not inline to datapath. So no impact on latency. It
consumes high CPU. Packetbeat can run as sidecar Docker container: https://www.elastic.co/guide/en/beats/packetbeat/current/running-on-docker.html
It supports various protocols https://www.elastic.co/guide/en/beats/packetbeat/current/exported-fields.html
It can capture all HTTP headers from request and
response https://www.elastic.co/guide/en/beats/packetbeat/current/exported-fields-http.html
Some more reference: https://www.elastic.co/products/beats/packetbeat
- Tranalyzer
is Lightweight open-source flow generator and packet analyzer for
practitioners and researchers
- Justniffer
is like tcpdump. Tcpdump is for TCP, while Justniffer for HTTP. Useful to
debug webserver.
https://github.com/reneluria/justniffer
5. Moloch is a large scale, open source, indexed packet capture and search system.
5. Moloch is a large scale, open source, indexed packet capture and search system.
Digital Certificate and SSL
Posted by
Manish Panchmatia
on Tuesday, September 17, 2019
Labels:
security,
software
/
Comments: (0)
Full article...>>
1. cryptographic algorithms,
1.1 Conventional cryptography (symmetric key)
1.2 Public Key cryptography
2. message digest functions, = one-way hash
3. digital signatures
Encrypt 1. digest 2. seq number 3. etc. using private key
Certificate
DER is based on BER. Digital certificate is converted to binary format using DER. Then Base64 convert + add prefix BEGIN + add suffix END = PEM format.
Cipher suite
1. Key Exchange Method : RSA, DH. with / without signature
2. Cipher for data transfer
2.1 No encryption
2.2 Steam cipher
2.3 Block cipher
3. Message Digest for creating MAC.
3.1 no digest
3.2 MD5
3.3 SHA
SSL Record Protocol between TCP and HTTP layers
1. Input from HTTP goes to RPU (Record Protocol Unit)
2. Compress input
3. add MAC
4. encrypt
5. output as TCP payload
1.1 Conventional cryptography (symmetric key)
1.2 Public Key cryptography
2. message digest functions, = one-way hash
3. digital signatures
Encrypt 1. digest 2. seq number 3. etc. using private key
Certificate
DER is based on BER. Digital certificate is converted to binary format using DER. Then Base64 convert + add prefix BEGIN + add suffix END = PEM format.
Cipher suite
1. Key Exchange Method : RSA, DH. with / without signature
2. Cipher for data transfer
2.1 No encryption
2.2 Steam cipher
2.3 Block cipher
3. Message Digest for creating MAC.
3.1 no digest
3.2 MD5
3.3 SHA
SSL Record Protocol between TCP and HTTP layers
1. Input from HTTP goes to RPU (Record Protocol Unit)
2. Compress input
3. add MAC
4. encrypt
5. output as TCP payload
TCPdump inside docker
For TCPDump 1
=============
k get pod productpage-v1-8554d58bff-rz25r -o json | grep containerID
docker exec ff8e6d1a169bc225ad1e357b54445e9055423189b900176bcc6cdd393f9cd83d /bin/bash -c 'cat /sys/class/net/eth0/iflink'
ip link | grep ^47
tcpdump -i
For TCPDump 2
=============
add
- name: tcpdump
image: corfr/tcpdump
command:
- /bin/sleep
- infinity
k get pod productpage-v1-8554d58bff-rz25r -o json | grep containerID
docker exec 867662a10a0324059b71d3be9765069b900eca4f2f5f29fdb2e7b7792fcfc726 tcpdump -s 0 -n -w /tmp/container.pcap
docker cp 867662a10a0324059b71d3be9765069b900eca4f2f5f29fdb2e7b7792fcfc726:/tmp/container.pcap .
=============
k get pod productpage-v1-8554d58bff-rz25r -o json | grep containerID
docker exec ff8e6d1a169bc225ad1e357b54445e9055423189b900176bcc6cdd393f9cd83d /bin/bash -c 'cat /sys/class/net/eth0/iflink'
ip link | grep ^47
tcpdump -i
For TCPDump 2
=============
add
- name: tcpdump
image: corfr/tcpdump
command:
- /bin/sleep
- infinity
k get pod productpage-v1-8554d58bff-rz25r -o json | grep containerID
docker exec 867662a10a0324059b71d3be9765069b900eca4f2f5f29fdb2e7b7792fcfc726 tcpdump -s 0 -n -w /tmp/container.pcap
docker cp 867662a10a0324059b71d3be9765069b900eca4f2f5f29fdb2e7b7792fcfc726:/tmp/container.pcap .
For TCPDump 3
=============
=============
1. run 'docker ps' at worker node.
get the container Id, for target container
2. get pid of that container
docker inspect --format '{{.State.pid}}' "Container ID from previous command"
3. nsenter -t "PID value from previous command" -n tcpdump


