当前位置:网站首页>How to view kubernetes API traffic by grabbing packets
How to view kubernetes API traffic by grabbing packets
2022-06-24 01:01:00 【Robert Lu】
When we go through kubectl Check it out. 、 modify Kubernetes Resource time , Have you ever thought about what the interface is like ? Is there any way to probe these interactive data ?
Kuberenetes The interface between client and server , Is based on http Agreed . So you just need to be able to capture and parse https Traffic , We can see kubernetes Of API Traffic .
But because of kubenetes The client private key is used to authenticate the client , So the packet capturing configuration should be a little more complex . The specific structure is as follows :
If you want to know more Kubernetes Knowledge of certificates , May have a look This article Kubernetes Certificate analysis article
from kubeconfig Extract the client certificate and private key
kubeconfig Contains the client's certificate and private key , We first have to extract them :
# Extract the client certificate
grep client-certificate-data ~/.kube/config | \
awk '{ print $2 }' | \
base64 --decode > client-cert.pem
# Extract the client private key
grep client-key-data ~/.kube/config | \
awk '{ print $2 }' | \
base64 --decode > client-key.pem
# Extract the server CA certificate
grep certificate-authority-data ~/.kube/config | \
awk '{ print $2 }' | \
base64 --decode > cluster-ca-cert.pemReference from Reddit
To configure Charles Agent software
As can be seen from the first picture , Agent software has two functions : One is receiving https Traffic and forward , Second, forward to kubernetes apiserver When , Use the specified client private key .
First configuration Charles, Let him intercept all https Traffic :
Then configure the client private key , That is, for sending to apiserver Request , Uniformly use the specified client private key for authentication :
To configure kubectl
Need to grab bags kubectl Of traffic , Two conditions are required :1. kubectl Use Charles Acting as agent ,2. kubectl Need to trust Charles Certificate .
# Charles The proxy port for is 8888, Set up https_proxy environment variable , Give Way kubectl Use Charles agent $ export https_proxy=http://127.0.0.1:8888/ # insecure-skip-tls-verify Indicates that the server certificate is not verified $ kubectl --insecure-skip-tls-verify get pod NAME READY STATUS RESTARTS AGE sc-b-7f5dfb694b-xtfrz 2/2 Running 0 2d20h
We can see get pod Your network request :
You can see ,get pod Of endpoint yes GET /api/v1/namespaces/<namespace>/pods.
Let's try again to create pod Request :
$ cat <<EOF >pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-robberphex
spec:
containers:
- name: nginx
image: nginx:1.14.2
EOF
$ kubectl --insecure-skip-tls-verify apply -f pod.yaml
pod/nginx-robberphex createdYou can also catch the bag :
establish pod Of endpoint yes POST /api/v1/namespaces/<namespace>/pods
To configure kubenetes client
Let's start by writing a with kubernetes go client To get pod Example ( Be careful , All certificates have been trusted in the code , So you can catch the bag ):
package main
/*
require (
k8s.io/api v0.18.19
k8s.io/apimachinery v0.18.19
k8s.io/client-go v0.18.19
)
*/
import (
"context"
"flag"
"fmt"
"path/filepath"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
func main() {
ctx := context.Background()
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err)
}
// Give Way clientset Trust all certificates
config.TLSClientConfig.CAData = nil
config.TLSClientConfig.Insecure = true
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err)
}
podClient := clientset.CoreV1().Pods(apiv1.NamespaceDefault)
podList, err := podClient.List(ctx, metav1.ListOptions{})
if err != nil {
panic(err)
}
for _, pod := range podList.Items {
fmt.Printf("podName: %s\n", pod.Name)
}
fmt.Println("done!")
}Then compile and execute :
$ go build -o kube-client $ export https_proxy=http://127.0.0.1:8888/ $ ./kube-client podName: nginx-robberphex podName: sc-b-7f5dfb694b-xtfrz done!
The same result can be caught at this time :
Based on this , We can analyze a Kubernetes What did you do , We also analyze Kubernetes The entrance to realization .
This article was first published in https://robberphex.com/lambda-causes-arthas-cant-redefine .
边栏推荐
- Experience summary of 9 Android interviews, bytes received, Ali, advanced Android interview answer
- [CVPR 2022] high resolution small object detection: cascaded sparse query for accelerating high resolution smal object detection
- ShardingSphere-proxy-5.0.0容量范围分片的实现(五)
- C language: sorting with custom functions
- Using anydesk remote control for intranet penetration horizontal movement
- version `ZLIB_1.2.9‘ not found (required by /lib64/libpng16.so.16)
- Theoretical analysis of countermeasure training: adaptive step size fast countermeasure training
- [shutter] how to use shutter packages and plug-ins
- C language: structure array implementation to find the lowest student record
- [technology planting grass] on the "double 11" of this year, Tencent cloud lightweight servers will be collected in a fair manner
猜你喜欢

What problems need to be solved by MES management system in the era of intelligent manufacturing

How to write peer-reviewed papers

GNN upper edge distributor! Instead of trying to refine pills, you might as well give your GNN some tricks

这不会又是一个Go的BUG吧?
![[machine learning] linear regression prediction](/img/74/9b5067bb9057049c998898ff2457f1.png)
[machine learning] linear regression prediction

WinSCP和PuTTY的安装和使用

数字化工厂可以分为哪两类

Cvpr2022 𞓜 thin domain adaptation

13 `bs_duixiang.tag标签`得到一个tag对象

C language: on the right shift of matrix
随机推荐
What should I pay attention to in the interview of artificial intelligence technology?
CVPR2022 | 可精简域适应
【小程序】实现双列商品效果
苹果Iphone14搭载北斗导航系统,北斗VS GPS有哪些优势?
实时计算框架:Flink集群搭建与运行机制
[CVPR 2020] conference version: a physics based noise formation model for extreme low light raw denoising
[technology planting grass] on the "double 11" of this year, Tencent cloud lightweight servers will be collected in a fair manner
Relationship between continuous testing and quality assurance
version `ZLIB_1.2.9‘ not found (required by /lib64/libpng16.so.16)
C语言:结构体数组实现找出最低分学生记录
Common core resource objects of kubernetes
WinSCP和PuTTY的安装和使用
Grab startup logcat
[OSG] OSG development (04) - create multiple scene views
Application configuration management, basic principle analysis
ARM学习(7) symbol 符号表以及调试
What is memory out of order access?
【Redis进阶之ZipList】如果再有人问你什么是压缩列表?请把这篇文章直接甩给他。
[CVPR 2020 oral] a physics based noise formation model for extreme low light raw denoising
numpy.linalg.lstsq(a,b,rcond=-1)解析