Programming Kubernetes - I


Meetup Event : https://www.meetup.com/kubernetes-openshift-India-Meetup/events/264123372/

on 24th August 2019


* Only API server interact with etcd

* Extend K8s

1. Extend life cycle of API server by adding new controller
2. add more APIs : by adding new API resource types and by adding CRDs
3. cluster daemons for automation. E.g. collecting metrics
4. cluster assist to extend functionality. E.g. SSL certificate manager. 


* Action or commands on K8s resources

1 create
2 read
- get
- list
- watch
3 update
- patch
- replace
4 delete

Here are all such actions/command on Deployment resource
https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/apps/v1/deployment.go

* API


apis///namespace//resource

Short form : GVR = group, version, resource 

Possible versions: 
Alpha (v1alpha1)
Beta (v1beata1)
Stable (v1)

* Few useful commands


kubectl api version
kubectl api-resource

we can get short names
kubectl get --raw 

* KIND used at YAML file is corrosponding to golang type. For any built-in K8s object:
1. https://github.com/kubernetes/api/blob/master///types.go has multiple struct in Go langugae corrpospond to each K8s object at YAML file.
2. https://github.com/kubernetes/client-go/tree/master/kubernetes/typed// folder has multiple files. Each file is corrsoponding to one K8s object. 
* K8s support for client library implemented in many languages: 
Official support for : Go, Python, Java, DotNet, JavaScript, Haskell
Many more language supported by community implementaiton
Please refer: https://kubernetes.io/docs/reference/using-api/client-libraries/ The source code is available at https://github.com/kubernetes-client
Out of all of them: client-go has cache and many more features. Kubectl and prometheus-operator also internally use client-go library. Important packages / utilities of client-go library are described at blog https://itnext.io/how-to-create-a-kubernetes-custom-controller-using-client-go-f36a7a7536cc E.g. Kubernetes, Discovery, Dynamic, Transport, Plugin, Scale, Util, tool/cache etc. tools/clientcmd package is useful to setup client from kubeconfig file. 

* Flatcar Linux: 

- an immutable Linux distribution for containers. 
- a friendly fork of CoreOS’s Container Linux and as such, compatible with it. 
- a self-updating operating system 
- It is designed for containers, making it ideal for running Kubernetes and other container platforms. 
- It aims to be an independently built, distributed, and supported Linux distribution designed for container workloads.
Reference : https://www.flatcar-linux.org/

* apimachienry
- Scheme, typing, encoding, decoding, and conversion packages for Kubernetes and Kubernetes-like API objects.
- This library is a shared dependency for servers and clients to work with Kubernetes API infrastructure without direct type dependencies. 
- Its first consumers are k8s.io/kubernetes, k8s.io/client-go, and k8s.io/apiserver.

* "~/.kube/config" path has all the security related file to interface with K8s master node (or minikybe) kubeconfig has context

* controller uses service account. secreat is mounted inside pod


* jq is a lightweight and flexible command-line JSON processor. It is like sed for JSON. Reference : https://stedolan.github.io/jq/

* YAML file consists 

1. api version
2. kind
3. matadata
4. spec
5. status
everything under metadata is in type of go language

Read Annotations
https://github.com/kubernetes/api/tree/master/core/v1
https://github.com/kubernetes/apimachinery/tree/master/pkg

Unit testing of controller with fake client

https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/client/fake/client_test.go

* Join K8s slack channel "k8sBLR"


Reference 

Go Client to communicate with K8s cluster: https://github.com/kubernetes/client-go


Schema of the external API types that are served by the Kubernetes API server: https://github.com/kubernetes/api 

All relevant blogs: https://kubernauts.dev/ 

PPT slide deck: https://docs.google.com/presentation/d/1NgAxNrUxcOnodm9VA4plidrKradQM_kAbrTrF844gec/edit#slide=id.g5dcf860567_4_3

Github accounts

https://github.com/surajssd
https://github.com/surajssd/lspods
Relevant blogs

https://kubernetes.io/blog/2018/01/introducing-client-go-version-6/
https://itnext.io/how-to-create-a-kubernetes-custom-controller-using-client-go-f36a7a7536cc
https://medium.com/speechmatics/how-to-write-kubernetes-custom-controllers-in-go-8014c4a04235
https://jvns.ca/blog/2017/06/04/learning-about-kubernetes/


Book
https://go.heptio.com/rs/383-ENX-437/images/Managing_Kubernetes.pdf
https://www.oreilly.com/library/view/programming-kubernetes/9781492047094/


https://stackoverflow.com/questions/49953980/watch-customresourcedefinitions-crd-with-client-go

0 comments:

Post a Comment