How to generate yaml template with kubectl command?

There’s the command create in kubectl that does the trick and replaced the run used in the past: let’s image you want to create a Deployment running a nginx:latest Docker image. # kubectl create deployment my_deployment –image=busybox –dry-run=client –output=yaml apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: my_deployment name: my_deployment spec: replicas: 1 selector: … Read more

How do you find the cluster & service CIDR of a Kubernetes cluster?

I spent hours searching for a generic way to do this. I gave up searching and wrote my own. As of Kubernetes 1.18, this method works across cloud providers, beyond just GKE. SVCRANGE=$(echo ‘{“apiVersion”:”v1″,”kind”:”Service”,”metadata”:{“name”:”tst”},”spec”:{“clusterIP”:”1.1.1.1″,”ports”:[{“port”:443}]}}’ | kubectl apply -f – 2>&1 | sed ‘s/.*valid IPs is //’) echo $SVCRANGE 172.21.0.0/16 This one liner works by feeding … Read more

Wait for kubernetes job to complete on either failure/success using command line

Run the first wait condition as a subprocess and capture its PID. If the condition is met, this process will exit with an exit code of 0. kubectl wait –for=condition=complete job/myjob & completion_pid=$! Do the same for the failure wait condition. The trick here is to add && exit 1 so that the subprocess returns … Read more

Can I connect one service account to multiple namespaces in Kubernetes?

You can simply reference a ServiceAccount from another namespace in the RoleBinding: apiVersion: rbac.authorization.k8s.io/v1beta1 kind: Role metadata: name: pod-reader namespace: ns2 rules: – apiGroups: [“”] resources: [“pods”] verbs: [“get”, “list”, “watch”] — apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: pod-reader-from-ns1 namespace: ns2 roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: pod-reader subjects: – kind: ServiceAccount name: ns1-service-account namespace: … Read more

How can I find the list of field selectors supported by kubectl for a given resource type?

The issue in your case is that you mistakenly use status.succeeded instead of status.successful, so right command is kubectl delete jobs.batch –field-selector status.successful==1 No resources found Regarding your question about all the fields: my suggestion is to deep into the code and search for proper resources types in conversion.go for each API. Example: Batch Jobs … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)