Deployment –> blueprints for app pod, how many replicas…
StatefulSet –> for DB replica sinc (DB are often hosted outside claster)
basic Architecture….
2 tipes of nodes. Master and Slave
3 process must run on every worker (slave) nod:
1. Container runtime, docker or something else
2. Kublet – Kubernati process
3. Kube proxy – forwards request
Master nod runs 4 processes:
1. API server: cluster gateway, authentication for deploying..client access, UI, cubectl, cubernati dashboard…etc
2. Scheduler… decide on which nod to put the pod (less used)
3. Controller manager…detects pod crashing and restarts them (cluster state changes)
4. ETCD key value store… cluster state info
minikube – for testing. master and worker nod on single machine.
minikube start –vm-driver=hyperkit
or docker, Hyper-V,KVM, Parallels, Virtual Box, VMware
kubectl get nodes
get status of nodes
minikube status
—– | | —–
kubectl version
display version
kubectl get pod (-o wide)
check pods (wide)
kubectl get services
check services
kubectl create deployment NAME –image=image
create deployment with pod in it
kubectl get deployment [name] (-o yaml)
check depooyment (3rd part, config status)
kubectl get replicaset
show replicas
kubectl edit deployment [name]
edit config file
kubectl logs [pod name]
for debagging
kubectl describe pod [pod name]
for debagging, more info
kubectl exec -it [pod_name] — bin/bash
get pod terminal
kubectl delete deployment [name]
rm pod
kubectl apply/delete -f [file_name]
create or delete deployment from config file (.yaml)
########
### config.yaml ### example ###
### eatch file is made of 3 parts ###
### metadata: ...names
### specification: ...any kind of config. attributs will be specific to the kind
### status: ...will be automatically generated by kubernates
###++++++++++++++++####
#### yaml file iz very strict about indentation - sintax ###
### tamplate: has its own metadata and spec. apply to pod ###
### Connection is established using labels and selectors ###
apiVersion: apps/v1
kind: deployment
metadata:
name: nginx-dpl
labels:
app: nginx
spec: ##### spec for deployment
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec: ##### spec for pod
containers:
- name: nginx
image: nginx:1.16
ports:
- containerPort: 80
Set Secret
### --- separate config (multiple conf in one file possible) ###
### deployment and service yaml goes in one file ###
### ConfigMap... external conf ###
apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-comfigmap
data:
databese_url: mongodb-service ### name of the service is URL
---
#### way to reference it..###
env:
- name: ME_CONFIG_MONGODB_SERVER
valueFrom:
configMapKeyRef:
name: mongodb-configmap
key: database_url
### externenal service for mongo UI ####
apiVersion: v1
kind: service
metadata:
name: mongo-express-service
spec:
selector:
app: mongo-express
type: LoadBalancer ### this make it external
ports:
- protocol: TCP
port: 8081
targetPort: 8081
nodePort: 30000 ### port for external IP you need to put in browser, 30000-32767
cubectl get namespace ### 4 default namespaces
default ### resources you make, goes here
kube-node-lease ### each node has associated lease
kube-public ### publicely accessible data
kube-system ### do NOT modify, for system use only
kubernates-dashboard ### minikube only
######################################
config file
#############
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-cfgmap
namespace: my-namespace
data:
db_url: mysql-service.database ### database is namespace
###############################
# each namespace must define own ConfigMap
# same for secret
# service can be shared beetween namespaces
# volumes and nod can not be namespaced
kubectl create namespace [namespace_name]
create new namespace
kubectl get configmap -n [my_namespace]
show configmap of specific namespace
cubens [my_namespace]
change default ns, cubectx has to be installed first.
Ingress – external access via domain (no ports)
apiVersion: v1
kind: service
metadata:
name: myapp-ext-service
spec:
selector:
app: myapp
type: LoadBalancer
ports:
- protocol: TCP
port: 8080
targetPort:8080
nodePort: 35010 ### public IP port
########################################
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadate:
name: myApp-ingress
spec:
rules:
- host: myapp.com ### entrypoint for end user
http: ### not browser http
paths: ### routing to internal service, url path
- backend:
serviceName: myapp-ext-service
servicePort: 8080 ### internal service port
Ingress controler, another pod that must be installed on nod to make ingress works. it manages redirections. k8s nginx ingress controler is from kubernates, but there are others.
minikube addons enabled ingress
starts and configure nginx ingress controler in minikube