Kubernetes: Difference between revisions
From wiki.vacula.xyz
(Created page with "== Concepts == Decoupling: * run resources anywhere * don't tie an application to a specific server * don't store configuration within the application") |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
* don't tie an application to a specific server | * don't tie an application to a specific server | ||
* don't store configuration within the application | * don't store configuration within the application | ||
== Usage == | |||
<nowiki> | |||
# Create a deployment of 3 nginx services called "salesweb" | |||
kubectl create deployment salesweb --image=nginx:latest --replicas=3 | |||
# Create a service for the salesweb deployment to use port 80 inside the containers | |||
kubectl expose deployment salesweb --port=80 | |||
# Tell the ingress controller to redirect any traffic (including sub-paths) on "sales.example.com" to the salesweb service | |||
kubectl create ingress salesweb --rule="sales.example.com/*=salesweb:80" | |||
</nowiki> | |||
== Tips and Tricks == | |||
Don't write YAML files directly, generate them. Use <code>kubectl create</code> with the options <code>--dry-run=client -o yaml</code> to generate the YAML files. Alternatively, use a <code>kubectl get</code> command with <code>-o yaml</code>. Use <code>kubectl apply -f</code> to create or update resources from a YAML file. | |||
Latest revision as of 20:44, 1 May 2025
Concepts
Decoupling:
- run resources anywhere
- don't tie an application to a specific server
- don't store configuration within the application
Usage
# Create a deployment of 3 nginx services called "salesweb" kubectl create deployment salesweb --image=nginx:latest --replicas=3 # Create a service for the salesweb deployment to use port 80 inside the containers kubectl expose deployment salesweb --port=80 # Tell the ingress controller to redirect any traffic (including sub-paths) on "sales.example.com" to the salesweb service kubectl create ingress salesweb --rule="sales.example.com/*=salesweb:80"
Tips and Tricks
Don't write YAML files directly, generate them. Use kubectl create with the options --dry-run=client -o yaml to generate the YAML files. Alternatively, use a kubectl get command with -o yaml. Use kubectl apply -f to create or update resources from a YAML file.