Skip to content

Instantly share code, notes, and snippets.

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mynamespace-user
namespace: mynamespace
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
@ipedrazas
ipedrazas / deployment.go
Created June 25, 2018 12:51
From kubectl to GO lang type
// Generated by https://quicktype.io
type Deployment struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata DeploymentMetadata `json:"metadata"`
Spec DeploymentSpec `json:"spec"`
Status Status `json:"status"`
@ipedrazas
ipedrazas / gist:8973dcd4b21a0eee6181391ce3e43445
Created June 8, 2018 14:17
Istio rule to allow apt-get update/install
cat <<EOF | istioctl replace -f -
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: ubuntu-archive-ext
spec:
hosts:
- archive.ubuntu.com
- security.ubuntu.com
ports:
@ipedrazas
ipedrazas / debug.md
Created May 24, 2018 10:17
Debugging issues in GKE

Pods have a big number of restarts

NAME                                     READY     STATUS    RESTARTS   AGE
details-v1-6798fccf5f-t7zqc              2/2       Running   0          22h
productpage-v1-5f7b97679-gn2js           2/2       Running   190        22h
ratings-v1-5675c99f79-66c96              2/2       Running   0          22h
reviews-v1-586cb488f9-cjxxz              2/2       Running   190        17h
reviews-v2-67ccbd89c7-4jgcr              2/2       Running   242        1d
reviews-v3-6fd9fddb9f-mczvf              2/2       Running   190        17h

Debugging in Kubernetes

"How do you debug applications running in Kubernetes?"

The strategy to successfully debugging applications in kubernetes is to be consistent with your approach: application to public traffic or public traffic to application.

The question as it is it's very generic, however, let's see the different components we might have to check in our debugging journey:

  • Container/Pod
  • Service
@ipedrazas
ipedrazas / gist:aa2b5550fd38446c131db0913e389b5e
Created April 23, 2018 13:31
instrument app - prometheus
// https://github.com/stefanprodan/k8s-podinfo/blob/master/pkg/server/instrument.go
func NewInstrument() *Instrument {
// used for monitoring and alerting (RED method)
histogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Subsystem: "http",
Name: "requests",
Help: "Seconds spent serving HTTP requests.",
Buckets: prometheus.DefBuckets,
}, []string{"method", "path", "status"})
@ipedrazas
ipedrazas / gist:c3c7bf6229f39a882052687c77c36d2e
Created April 18, 2018 13:45
ubuntu in kube-system as admin
kubectl run my-shell --rm -i --tty --image ubuntu --serviceaccount tiller --namespace kube-system -- bash
@ipedrazas
ipedrazas / gist:86e275472d376be9dbf06a7b9eeeaf09
Created April 12, 2018 13:27
signal hander to gracefully exit in Go
// setup a signal hander to gracefully exit
func sigHandler() <-chan struct{} {
stop := make(chan struct{})
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c,
syscall.SIGINT, // Ctrl+C
syscall.SIGTERM, // Termination Request
syscall.SIGSEGV, // FullDerp
syscall.SIGABRT, // Abnormal termination
@ipedrazas
ipedrazas / gist:926bd0ef8632c778cf0efda3c2aaf19c
Created April 10, 2018 10:14
create lab cluster with expiry date
gcloud beta container \
--project "kubernetes-prototype-197913" \
clusters create "lab-1" \
--zone "europe-west2-a" \
--username "admin" \
--cluster-version "1.9.6-gke.0" \
--machine-type "n1-standard-1" \
--image-type "COS" \
--disk-size "100" \
--node-labels expiry=20180411,env=lab \
kubectl get pods --all-namespaces -o json \
| jq -r '.items[] | \
select(.status.phase != "Running" or ([ .status.conditions[] | \
select(.type == "Ready" and .state == false) ] | length ) == 1 ) | \
.metadata.namespace + "/" + .metadata.name'