Last active
May 31, 2023 17:22
-
-
Save rahuls360/b3eacde5b2fff1978768b8549a34dc1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
ingress-nginx-admission-patch CrashLoopBackOff
error
- Reset your k8s instance & restart your docker desktop and try.
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
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
Ensure your ingress-nginx is running. If you are using docker-desktop, then run the below command.
Reference