# cat clusterIP.yaml
apiVersion: v1
kind: Service
metadata:
name: my-internal-service
spec:
selector:
app: my-app
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
You can create the Service by using kubectl apply -f clusterIP.yaml. After you create the Service, you can use kubectl get service to see the stable IP addressDevOps Space
Sunday, July 24, 2022
Create Kubernetes ClusterIP Service Definition using YAML
Create kubernetes NodePort service using yaml
# cat NodePort.yaml
apiVersion: v1
kind: Service
metadata:
name: my-nodeport-service
spec:
selector:
app: my-app
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
nodePort: 30036
protocol: TCP
Run following command to create NodePort service in your Kubernetes cluster
# kubectl apply -f NodePort.yaml
Create Kubernetes Pod Definition using YAML
# cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
role: myrole
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
Run following command to create pod in your Kubernetes cluster
# kubectl apply -f pod.yaml
Tuesday, June 21, 2022
How to Restart the pods in Kubernetes
A pod is a collection of containers sharing a network, acting as the basic unit of deployment in Kubernetes. All containers in a pod are scheduled on the same node.
1: kubectl scale
Scale the number of replicas using the kubectl command scale and set the replicas flag to zero:
kubectl scale deployment <deployment_name> --replicas=0 -n <namespace>
Scale the number of replicas using the kubectl command scale and set the replicas flag to its original value:
kubectl scale deployment <deployment_name> --replicas=2 -n <namespace>
2: kubectl rollout restart
kubectl rollout restart deployment <deployment_name> -n <namespace>
3: kubectl delete pod
It will automatically recreate the pod to keep it consistent with the expected one.
kubectl delete pod <pod_name> -n <namespace>
Create Kubernetes ClusterIP Service Definition using YAML
A ClusterIP service is the default Kubernetes service. It gives you a service inside your cluster that other apps/pods inside your cluster c...