Skip to content

Commit 8abbab9

Browse files
committed
Complete the Guide
1 parent a92cf90 commit 8abbab9

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

README.md

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ This is not a comprehensive guide to learn Kubernetes from scratch, rather this
6161
- [AppServer Full Spec](#appserver-full-spec)
6262
1. [**Understanding** advance kubernetes resources](#advance-kubernetes-resources):
6363
- [Namespaces](#namespaces)
64+
- [Create Namespace and Add Resource](#creating-namespace-&-adding-resource)
6465
- [Context](#context)
65-
- [Config](#config)
6666
1. [**Cheat sheet**](#cheat-sheet)
67-
1. **Next steps**
67+
1. [**Next steps**](#next-steps)
6868

6969

7070

@@ -976,3 +976,109 @@ spec:
976976
```
977977
Quickly apply it with `kubectl apply -f appserver-spec.yml`
978978

979+
980+
## Understanding Advance Kubernetes Resources
981+
982+
### Namespace
983+
Namespace are software level cluster virtualization over same physical k8s cluster.
984+
```bash
985+
root@vagrant:/home/vagrant# kubectl get ns
986+
NAME STATUS AGE
987+
default Active 19d
988+
kube-node-lease Active 19d
989+
kube-public Active 19d
990+
kube-system Active 19d
991+
```
992+
993+
Kubernetes starts with 4 namespaces:
994+
1. **default**: The default namespace for objects with no other namespace.
995+
2. **kube-system**: The namespace for objects created by the Kubernetes system.
996+
3. **kube-public**: This namespace is created automatically and is readable by all users (including those not **authenticated**). This namespace is mostly reserved for cluster usage, in case that some resources should be visible and readable publicly throughout the whole cluster. The public aspect of this namespace is only a convention, not a requirement.
997+
4. **kube-node-lease**: This namespace for the lease objects associated with each node which improves the performance of the node heartbeats as the cluster scales.
998+
999+
Get Pods from specific namespace
1000+
``kubectl get pods --namespace=default`` OR `kubectl get pods -n default`
1001+
```bash
1002+
root@vagrant:/home/vagrant# kubectl get pods --namespace=kube-system
1003+
NAME READY STATUS RESTARTS AGE
1004+
coredns-f9fd979d6-g9wxg 1/1 Running 5 19d
1005+
coredns-f9fd979d6-zrdvs 1/1 Running 5 19d
1006+
etcd-vagrant 1/1 Running 5 19d
1007+
kube-apiserver-vagrant 1/1 Running 5 19d
1008+
kube-controller-manager-vagrant 1/1 Running 7 19d
1009+
kube-flannel-ds-64l2p 1/1 Running 6 19d
1010+
kube-proxy-4j4kw 1/1 Running 5 19d
1011+
kube-scheduler-vagrant 1/1 Running 7 19d
1012+
```
1013+
1014+
#### Creating Namespace & Adding resource
1015+
- Create namespace : `kubectl create namespace qa`
1016+
- Once the namespace is created, just add the metadata field : `namespace: qa`, [File](files/pod-qa.yml)
1017+
```diff
1018+
apiVersion: v1
1019+
kind: Pod
1020+
metadata:
1021+
name: nginx
1022+
++ namespace: qa
1023+
spec:
1024+
containers:
1025+
- name: nginx
1026+
image: nginx
1027+
```
1028+
- Most Kubernetes resources (e.g. pods, services, replication controllers, and others) are in some namespaces. However namespace resources are not themselves in a namespace. And low-level resources, such as nodes and persistentVolumes, are not in any namespace.
1029+
- To see the list of resource not in namespace : `kubectl api-resources --namespaced=false`
1030+
1031+
### Context
1032+
- Is a tuple of **cluster**, **user**, **namespace**. This is useful when you connect to multiple clusters from one control plane.
1033+
- Get the current context: `kubectl config get-contexts`
1034+
```bash
1035+
root@vagrant:/home/vagrant/kubedata# kubectl config get-contexts
1036+
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
1037+
* kubernetes-admin@kubernetes kubernetes kubernetes-admin
1038+
```
1039+
- You can create kubernetes context using config file or using commands.
1040+
- Create a qa-config: `kubectl config set-context dev-env --cluster=kubernetes --user=new-admin --namespace=dev-env`
1041+
```bash
1042+
root@vagrant:/home/vagrant/kubedata# kubectl config set-context dev-env --cluster=kubernetes --user=new-admin --namespace=dev-env
1043+
Context "dev-env" created.
1044+
```
1045+
```bash
1046+
root@vagrant:/home/vagrant/kubedata# kubectl config get-contexts
1047+
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
1048+
dev-env kubernetes new-admin dev-env
1049+
* kubernetes-admin@kubernetes kubernetes kubernetes-admin
1050+
```
1051+
- Now use the created context using : `kubectl config use-context dev-env`
1052+
- All your k8s resource will now be in DEV name space under kubernetes cluster :smile:
1053+
- But to create resource you will need user `new-admin` authentication. This is the user created during context creation.
1054+
- Create username & password for user `new-admin` to use the resource in context and create a role binding: **Run this before switching context**
1055+
`kubectl config set-credentials new-admin --username=adm --password=changeme`
1056+
```bash
1057+
cat << EOF | kubectl apply -f -
1058+
apiVersion: rbac.authorization.k8s.io/v1
1059+
kind: ClusterRoleBinding
1060+
metadata:
1061+
name: new-admin
1062+
roleRef:
1063+
apiGroup: rbac.authorization.k8s.io
1064+
kind: ClusterRole
1065+
name: cluster-admin
1066+
subjects:
1067+
- apiGroup: rbac.authorization.k8s.io
1068+
kind: User
1069+
1070+
1071+
EOF
1072+
```
1073+
1074+
## CheatSheet
1075+
- I plan to write a simple cheat sheet covering the commands in this repo. But for now Try : [k8s-official-cheat-sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)
1076+
1077+
## Next Steps
1078+
- [In detail K8s Reference](https://kubernetes.io/docs/reference/)
1079+
- [API Guide](https://kubernetes.io/docs/reference/)
1080+
- [CLI Guide](https://kubernetes.io/docs/reference/)
1081+
- [K8s Design Docs](https://kubernetes.io/docs/reference/)
1082+
- Raising a PR makes me happy, take that as a next step.
1083+
- Issues are more than welcome.
1084+
- If you like it, share it.

files/pod-qa.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: nginx
5+
namespace: qa
6+
spec:
7+
containers:
8+
- name: nginx
9+
image: nginx

0 commit comments

Comments
 (0)