Skip to content

Instantly share code, notes, and snippets.

@rahuls360
Last active May 31, 2023 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahuls360/8c916bf808fbe41a3cc7721417cfa246 to your computer and use it in GitHub Desktop.
Save rahuls360/8c916bf808fbe41a3cc7721417cfa246 to your computer and use it in GitHub Desktop.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment # k8s deployment creates pods (instances of containers) and ensures the spec mentioned below is maintained (declarative)
spec:
selector:
matchLabels:
app: nginx-app # container name - used for ensure replica count is always maintained
replicas: 1 # no of pods to run
template:
metadata:
labels:
app: nginx-app # container name
spec:
containers:
- name: nginx-app # container name
image: my-nginx-image # docker image name. Have this build already
imagePullPolicy: Never # Don't pull from remote docker registry during local testing
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service # a service exposes deployments/pods to other microservices in our cluster/external traffic
spec:
selector:
app: nginx-app # container name
ports:
- name: http
port: 80
targetPort: 80
@rahuls360
Copy link
Author

rahuls360 commented May 31, 2023

// Build docker image using our dockerfile (refer the other gist)
docker build -t my-nginx-image -f Dockerfile .

// Create k8s resources mention in our file - i.e. Deployment and Service
kubectl apply -f nginx-deploy.yml

// Used for exposing traffic from localhost to docker instances (inside kubernetes cluster) - Access using localhost:8080
kubectl port-forward service/nginx-service 8080:80 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment