Recapping how to run this locally
Course: Kubernetes Part 2 - chapter 3
Creating a cluster
Section titled “Creating a cluster”- Create a
kind.ymlfile locally
kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes:- role: control-plane extraPortMappings: - containerPort: 30007 hostPort: 30007- role: worker extraPortMappings: - containerPort: 30007 hostPort: 30008- role: worker- Run the cluster locally
kind create cluster --config kind.yml --name local2- Run docker ps to confirm that the cluster is running
docker psCreating a pod
Section titled “Creating a pod”- Create a pod manifest (pod.yml)
apiVersion: v1kind: Podmetadata: name: nginxspec: containers: - name: nginx image: nginx ports: - containerPort: 80- Apply the pod manifest
kubectl apply -f pod.yml- Check if the pod exists now
kube get pods- Check the logs
kubectl logs -f nginx- Delete the pod
kubectl delete pod nginxCreating a replicaset
Section titled “Creating a replicaset”- Create the replicaset manifest
apiVersion: apps/v1kind: ReplicaSetmetadata: name: nginx-replicasetspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80- Apply the replicaset manifest
kubectl apply -f rs.yml- Check the number of pods running now
kubectl get pods- Try deleting a pod, and ensure it gets restarted
- Delete the replicaset
kubectl delete rs nginx-replicasetCreating a Deployment
Section titled “Creating a Deployment”- Create a deployment manifest (deployment.yml)
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80- Apply the manifest
kubectl apply -f deployment.yml- Check the
rsthat exist now
kubectl get rs- Check the pods that exist now
kubectl get pods- Try creating a new deployment with a wrong image name
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx2:latest ports: - containerPort: 80- Ensure that the old pods are still running
kubectl get podsKeep the deployment, it’ll come in handy in the 4th slide