Kubernetes
Kubernetes
Below Commands on Both Master - Slave(worker) Node (run command as root user)
Enter the commands shown as output as a regular user(ubuntu). Copy and keep your
join command for slave node
(Note you will get this join command in your master node after kubeadm init)
Manifests
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx-container
image: nginx
ports:
- containerPort: 80
apply manifest
list pods
Describe pod
check logs
or
Delete pod
or
list namespace
kubectl get ns
or
Create ns
delete ns
Replicaset:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-replicaset
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx
ports:
- containerPort: 80
Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx:1.7.1
ports:
- containerPort: 80
Services
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
type: NodePort
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30080
access: awsec2publicip:30080
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
type: ClusterIP
ports:
- protocol: TCP
port: 80
targetPort: 80
test curl
go inside centos pod
kubectl exec -it pod/centos-pod -n test -- /bin/bash
or
kubectl exec -it pod/centos-pod -n test -- sh
curl clusterip:80
Kubernetes Ingress
Configuration
kubectl apply -f
https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/
deploy/static/provider/baremetal/deploy.yaml
Ingressroute:
apiVersion: v1
kind: Ingress
metadata:
name: nginx-ingress
spec:
rules:
- host: xyz.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
Kubernetes Dashboard
Configuration
Step 1: Apply manifest
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/
deploy/recommended.yaml
type: NodePort
Step 4:
HPA config:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx-deployment
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 60
d