Skip to content

Instantly share code, notes, and snippets.

@rahuls360
Last active May 31, 2023 17:22
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/b3eacde5b2fff1978768b8549a34dc1a to your computer and use it in GitHub Desktop.
Save rahuls360/b3eacde5b2fff1978768b8549a34dc1a 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
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
@rahuls360
Copy link
Author

Ensure your ingress-nginx is running. If you are using docker-desktop, then run the below command.
Reference

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.0/deploy/static/provider/cloud/deploy.yaml

@rahuls360
Copy link
Author

ingress-nginx-admission-patch CrashLoopBackOff error

  • Reset your k8s instance & restart your docker desktop and try.

@rahuls360
Copy link
Author

rahuls360 commented May 31, 2023

Apply changes
kubectl apply-f nginx-deploy.yml

  • Suitable for 1st usage
  • Worked inconsistently for me. Maybe it failed due to high CPU usage. Started working fine later.
  • Reference1, Reference2

Subsequent changes
kubectl replace -f nginx-deploy.yml

To delete the resources created from the file
kubectl delete -f nginx-deploy.yml

@rahuls360
Copy link
Author

As per ChatGPT
apply -> Create/update (preserves metadata/fields)
replace -> Update -> Replaces existing resource with a new one

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