• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

? Deploying Your First App on Kubernetes (With YAML Examples)

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Kubernetes can feel overwhelming at first , all the YAML, pods, deployments, services... But once you deploy your first app, things start to click.

In this guide, we’ll walk through deploying a simple Nginx web server to a Kubernetes cluster, using just a few YAML files.

? What We’re Deploying


We’ll use:

  • A Deployment – to manage our pods
  • A Service – to expose our app
  • Optionally, a NodePort – to access it from a browser
? Step 1: Create a Deployment


Let’s create a deployment to run two replicas of the nginx container.

File: nginx-deployment.yaml


apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80

Apply it:


kubectl apply -f nginx-deployment.yaml

Check status:


kubectl get deployments
kubectl get pods
? Step 2: Expose the App with a Service


To make the app accessible, define a Service.

File: nginx-service.yaml


apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort

Apply it:


kubectl apply -f nginx-service.yaml

Check the port:


kubectl get svc nginx-service
Look for the NodePort, e.g., 30007.
? Step 3: Access the App

  • If you're using Minikube:

minikube service nginx-service
  • If you're using Docker Desktop or a cloud cluster:

Open http://<NODE-IP>:<NODE-PORT> in your browser.

? Bonus: Clean Up


To delete the resources:


kubectl delete -f nginx-deployment.yaml
kubectl delete -f nginx-service.yaml
? Summary


You just:

  1. Created a Kubernetes deployment for Nginx
  2. Exposed it using a service
  3. Accessed it via browser or CLI
  4. Learned the basics of kubectl and YAML syntax
? Next Steps


Try:

  • Replacing Nginx with your own app image
  • Using ConfigMaps or Secrets for configuration
  • Exploring Ingress controllers
  • Scaling your deployment with kubectl scale

#kubernetes #devops #k8s #containers #yaml #cloudnative


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу