我已经部署了Kubernetes服务,当我查询以获取部署$ kubectl get deployments
时,可以看到部署。
部署的json
如下所示
apiVersion: v1
kind: Deployment
metadata:
name: test
spec:
replicas: 1
template:
metadata:
labels:
app: test
release: testRelease
customProp: xyz
我的问题是,如何通过指定'customProp'值来构成一个查询,以获取部署。 kubectl
是否支持在查询中传递jsonpath?这样我就可以传递json
之类的jsonpath='{$.spec.template.metadata.labels.customProp}'
路径,并以'xyz'的形式对此JSONPath赋值。
这就是我要执行的操作:
$ kubectl get deployments -n <namespace> <json path query>
但是不确定如何构造json
路径查询并与$kubectl get deployments
一起传递。
答案 0 :(得分:2)
Kubectl确实支持query feature,您可以在下面的查询中使用
kubectl get pods --selector=customProp=xyz
Kubectl也支持JSON路径表达式,要获取更多详细信息,请遵循link。您可以按照链接上显示的语法编写查询。
答案 1 :(得分:1)
是的,可以使用jsonpath向class customPin: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?
init(pinTitle:String, pinSubTitle:String, location:CLLocationCoordinate2D) {
self.title = pinTitle
self.subtitle = pinSubTitle
self.coordinate = location
}
}
var mapView: MKMapView!
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
let location = CLLocationCoordinate2D(latitude: 32.2325, longitude:76.3242)
let region = MKCoordinateRegion(center: location, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005))
self.mapView.setRegion(region, animated: true)
let pin = customPin(pinTitle: "Honory Dalailama Temple", pinSubTitle: "Dharamshala, Himachal Pradesh, India", location: location)
self.mapView.addAnnotation(pin)
self.mapView.delegate = self
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "customannotation")
annotationView.image = UIImage(named:"pin")
annotationView.canShowCallout = true
return annotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
print("annotation title == \(String(describing: view.annotation?.title!))")
}
fileprivate func setupLocationManager() {self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() == true {
if CLLocationManager.authorizationStatus() == .restricted || CLLocationManager.authorizationStatus() == .denied || CLLocationManager.authorizationStatus() == .notDetermined {
locationManager.requestWhenInUseAuthorization()
}
locationManager.desiredAccuracy = 1.0
locationManager.delegate = self
locationManager.startUpdatingLocation()
} else {
print("PLease turn on location services or GPS")
}
}
fileprivate func setupMapView() {
let mView = MKMapView(frame: CGRect(x: 0, y: 20, width: view.frame.width, height: view.frame.height))
mView.showsUserLocation = true
view.addSubview(mView)
mView.showsScale = true
mView.showsPointsOfInterest = true
mView.showsTraffic = true
mView.showsCompass = true
mView.userTrackingMode = .follow
self.mapView = mView
}
查询资源。运行以下命令以获取所需内容:
kube-apiserver
有关更多用法,请参见https://kubernetes.io/docs/reference/kubectl/jsonpath。
答案 2 :(得分:0)
为部署对象添加标签。然后使用下面的命令查询特定的部署
kubectl获取部署-l labelname = labelvalue