[CKA] 002. Kubernetes Objects
ReplicaSet, Deployment, Services, Namespace, Help Commands

- hpyYh
- 2 min read

ReplicaSet
- For high availablility
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
tier: fronted
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
tier: fronted
- kubectl get rs
- kubectl apply -f replicaset.yaml
- kubectl scale –replicas=5 rs myapp-replicaset
- kubectl edit rs myapp-replicaset
Deployment
- deployment > replicaset > pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
type: front-end
spec:
replicas: 3
selector:
matchLabels:
app: myapp
tier: fronted
template:
metadata:
labels:
app: myapp
tier: fronted
spec:
containers:
- name: nginx-container
image: nginx
useful tip!
kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml
Services
- NodePort : external user <-> NodePort <-> pod
apiVersion: v1
kind: Service
metadata:
name: myapp-nodeport
spec:
type: NodePort
ports:
- port: 80
nodePort: 30008
selector:
app: myapp
tier: fronted
- ClusterIP
apiVersion: v1
kind: Service
metadata:
name: myapp-nodeport
spec:
type: ClusterIp
ports:
- port: 80
nodePort: 30008
selector:
app: myapp
tier: fronted
- LoadBalancer
apiVersion: v1
kind: Service
metadata:
name: myapp-nodeport
spec:
type: LoadBalancer
ports:
- port: 80
nodePort: 30008
selector:
app: myapp
tier: fronted
- what endpoint count? : connected pod port count
Namespace
- same namesapce connect : service
- diff namespace connect : service.namespace.svc.cluster.local
- kubectl get pod –namespace=dev (-n=dev)
Help Commands
apply
- declarative (not imperative)
- create, edit, replace => apply
api-resource
- list resource types
explain
- object documentation
- kubectl explain
- kubectl explain
. - kubectl explain
–recursive
- tags :
- Cka