在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):iovisor/kubectl-trace开源软件地址(OpenSource Url):https://github.com/iovisor/kubectl-trace开源编程语言(OpenSource Language):Go 92.1%开源软件介绍(OpenSource Introduction):
InstallingKrewYou can install Once you have Krew installed just run: kubectl krew install trace You're ready to go! Pre-built binariesSee the release page for the full list of pre-built assets. The commands here show Linux curl -L -o kubectl-trace.tar.gz https://github.com/iovisor/kubectl-trace/releases/download/v0.1.0-rc.1/kubectl-trace_0.1.0-rc.1_linux_amd64.tar.gz
tar -xvf kubectl-trace.tar.gz
mv kubectl-trace /usr/local/bin/kubectl-trace OSX curl -L -o kubectl-trace.tar.gz https://github.com/iovisor/kubectl-trace/releases/download/v0.1.0-rc.1/kubectl-trace_0.1.0-rc.1_darwin_amd64.tar.gz
tar -xvf kubectl-trace.tar.gz
mv kubectl-trace /usr/local/bin/kubectl-trace Windows In PowerShell v5+ $url = "https://github.com/iovisor/kubectl-trace/releases/download/v0.1.0-rc.1/kubectl-trace_0.1.0-rc.1_windows_amd64.zip"
$output = "$PSScriptRoot\kubectl-trace.zip"
Invoke-WebRequest -Uri $url -OutFile $output
Expand-Archive "$PSScriptRoot\kubectl-trace.zip" -DestinationPath "$PSScriptRoot\kubectl-trace" SourceUsing go modules, you can build kubectl-trace at any git tag:
This will download and compile To keep track of the ref you used to build, you can add an ldflag at build time to set this to match the ref provided to go modules:
Note: It is recommended you build tagged revisions only if you are looking for stability. Building branches such as PackagesYou can't find the package for your distro of choice? You are very welcome and encouraged to create it and then open an issue to inform us for review. Arch - AURThe official PKGBUILD is on AUR. If you use
ArchitectureSee architecture.md UsageYou don't need to setup anything on your cluster before using it, please don't use it already on a production system, just because this isn't yet 100% ready. Run a program from string literalIn this case we are running a program that probes a tracepoint
on the node
Run a program from fileHere we run a program named
Run a program against a PodThat pod has a Go program in it that is at The purpose of this program is to load an Since What you do then is that you get the
Running against a Pod vs against a NodeIn general, you run kprobes/kretprobes, tracepoints, software, hardware and profile events against nodes using the When you want to actually probe an userspace program with an uprobe/uretprobe or use an user-level static tracepoint (usdt) your best
bet is to run it against a pod using the It's always important to remember that running a program against a pod, as of now, is just a facilitator to find the process id for the binary you want to probe on the root process namespace. You could do the same thing when running in a Node by knowing the pid of your process yourself after entering in the node via another medium, e.g: ssh. So, running against a pod doesn't mean that your bpftrace program will be contained in that pod but just that it will pass to your program some
knowledge of the context of a container, in this case only the root process id is supported via the Using a custom service accountBy default If you need to pass a service account you can use the kubectl trace run --serviceaccount=kubectltrace ip-180-12-0-152.ec2.internal -f read.bt Executing in a cluster using Pod Security PoliciesIf your cluster has pod security policies you will need to make so that That service account, then will need to be in a group that uses the proper privileged First, create the service account that you will use with apiVersion: v1
kind: ServiceAccount
metadata:
name: kubectltrace
namespace: default Now that we have a apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: kubectltrace
spec:
fsGroup:
rule: RunAsAny
privileged: true
runAsUser:
rule: RunAsAny
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- '*'
allowedCapabilities:
- '*'
hostPID: true
hostIPC: true
hostNetwork: true
hostPorts:
- min: 1
max: 65536 Ok, this Now with a You can change the apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kubectltrace-psp
rules:
- apiGroups:
- policy
resources:
- podsecuritypolicies
resourceNames:
- kubectltrace
verbs:
- use
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubectltrace-psp
subjects:
- kind: ServiceAccount
name: kubectltrace
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubectltrace-psp OK! Now that we are all set we can just run the program by specifying the service account we just created and it will use our pod security policy! kubectl trace run --serviceaccount=kubectltrace ip-180-12-0-152.ec2.internal -f read.bt If you used a different namespace other than default for your service account, you will want to specify the namespace too, like this: kubectl trace run --namespace=mynamespace --serviceaccount=kubectltrace ip-180-12-0-152.ec2.internal -f read.bt Using a patch to customize the trace jobThere may be times when you need to customize the job descriptor that kubectl-trace generates. You can provide a patch file that will modify any of the job's attributes before it executes on the cluster. The
Patch strategies The supported patch strategies are the same as those used by Kubernetes to support in-place API object updates. These 3 patch strategies are:
Note: You can create your patch files in either YAML or JSON format. The format is independent of the strategy used, e.g. the strategy Example: customizing resource limits A cluster administrator may have set strict resource limits that conflict with the defaults used by Below is an example of a YAML patch which uses the The patch below replaces the first container's resources section, in order to increase both the request and limit values for cpu and memory: # mypatch.yaml
- op: replace
path: /spec/template/spec/containers/0/resources
value:
limits:
cpu: 2
memory: 500Mi
requests:
cpu: 2
memory: 500Mi We can now run the job using our patch: kubectl trace run ip-180-12-0-152.ec2.internal -f read.bt --patch mypatch.yaml --patch-type json Example: setting an environment variable The following JSON format patch adds a [
{
"op": "add",
"path": "/spec/template/spec/containers/0/env",
"value": [{ "name": "BPFTRACE_STRLEN", "value": "128" }]
}
] kubectl trace run ip-180-12-0-152.ec2.internal -f read.bt --patch mypatch.json --patch-type json More bpftrace programsNeed more programs? Look here. ContributingAlready pumped up to commit some code? Here are some resources to join the discussions in the IOVisor community and see what you want to work on.
Special thanks to Ramon Gilabert for the logo. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论