{"id":1478,"date":"2024-12-10T14:10:43","date_gmt":"2024-12-10T14:10:43","guid":{"rendered":"https:\/\/kb.lagonet.vn\/?p=1478"},"modified":"2024-12-10T14:10:43","modified_gmt":"2024-12-10T14:10:43","slug":"ingress","status":"publish","type":"post","link":"https:\/\/kb.lagonet.vn\/?p=1478","title":{"rendered":"INGRESS"},"content":{"rendered":"\n<p>Here is a detailed step-by-step guide based on the instructions you&#8217;ve provided:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Install Helm<\/strong><\/h3>\n\n\n\n<p>Run the following command to install Helm on your system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sSL https:\/\/raw.githubusercontent.com\/helm\/helm\/master\/scripts\/get-helm-3 | bash\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Deploy NGINX Ingress Controller<\/strong><\/h3>\n\n\n\n<p>Use Helm to deploy the NGINX Ingress Controller:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>helm upgrade --install ingress-nginx ingress-nginx \\\n  --repo https:\/\/kubernetes.github.io\/ingress-nginx \\\n  --namespace ingress-nginx --create-namespace\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This command installs the Ingress Controller into the namespace <code>ingress-nginx<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>Verify the installation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get all --namespace=ingress-nginx\n<\/code><\/pre>\n\n\n\n<p>Check the service <code>ingress-nginx-controller<\/code> to find the NodePort:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get svc --namespace=ingress-nginx\n<\/code><\/pre>\n\n\n\n<p>Access the default &#8220;Not Found&#8221; page to confirm that the Ingress Controller is working:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;&lt;Public-IP&gt;:&lt;NodePort&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Create a Namespace for Your Application<\/strong><\/h3>\n\n\n\n<p>Create a namespace called <code>webphp<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl create ns webphp\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Deploy a Demo Application<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Deploy a simple application using the <code>httpd<\/code> image: <code>kubectl create deployment demo --image=httpd --port=80 -n webphp<\/code><\/li>\n\n\n\n<li>Expose the deployment as a service: <code>kubectl expose deployment demo -n webphp<\/code><\/li>\n\n\n\n<li>Verify the deployment and service: <code>kubectl get all -o wide -n webphp<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 5: Create an Ingress Resource<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a file named <code>ingressdemo.yaml<\/code> with the following content: <code>apiVersion: networking.k8s.io\/v1 kind: Ingress metadata: name: python-ingress namespace: webphp spec: ingressClassName: nginx rules: - host: \"www.ccnapnh.fun\" http: paths: - path: \/ pathType: Prefix backend: service: name: demo port: number: 80<\/code><\/li>\n\n\n\n<li>Apply the Ingress configuration: <code>kubectl apply -f ingressdemo.yaml<\/code><\/li>\n\n\n\n<li>Check if the Ingress is created successfully: <code>kubectl get ingress -n webphp<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 6: Access the Application<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Update your DNS records for <code>www.ccnapnh.fun<\/code>:\n<ul class=\"wp-block-list\">\n<li>Create an <code>A<\/code> record pointing to the public IP of your Kubernetes cluster (e.g., <code>18.162.52.233<\/code>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Test the application using the <code>curl<\/code> command: <code>curl -i &lt;Cluster-Public-IP>:&lt;NodePort> -H 'Host: www.ccnapnh.fun'<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 7: Enable HTTPS with Let\u2019s Encrypt<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install <code>certbot<\/code>: <code>sudo apt install letsencrypt<\/code><\/li>\n\n\n\n<li>Generate SSL certificates: <code>sudo certbot certonly --standalone --agree-tos --preferred-challenges http -d www.ccnapnh.fun -v<\/code><\/li>\n\n\n\n<li>Verify the certificates: <code>sudo ls \/etc\/letsencrypt\/live\/www.ccnapnh.fun\/<\/code><\/li>\n\n\n\n<li>Create a Kubernetes Secret: <code>kubectl create secret tls phpsecret \\ --key \/etc\/letsencrypt\/live\/www.ccnapnh.fun\/privkey.pem \\ --cert \/etc\/letsencrypt\/live\/www.ccnapnh.fun\/fullchain.pem \\ -n webphp<\/code><\/li>\n\n\n\n<li>Confirm the secret: <code>kubectl get secret -n webphp<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 8: Update Ingress Resource for HTTPS<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Update the <code>ingressdemo.yaml<\/code> file to include TLS: <code>apiVersion: networking.k8s.io\/v1 kind: Ingress metadata: name: python-ingress namespace: webphp spec: ingressClassName: nginx rules: - host: \"www.ccnapnh.fun\" http: paths: - path: \/ pathType: Prefix backend: service: name: demo port: number: 80 tls: - hosts: - www.ccnapnh.fun secretName: phpsecret<\/code><\/li>\n\n\n\n<li>Apply the updated Ingress configuration: <code>kubectl apply -f ingressdemo.yaml<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 9: Verify the Setup<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Test the HTTPS connection to your domain: <code>curl -k https:\/\/www.ccnapnh.fun<\/code><\/li>\n\n\n\n<li>Visit your website in a browser:\n<ul class=\"wp-block-list\">\n<li>Ensure the SSL certificate is applied correctly.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 10: Automate Certificate Renewal<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check the <code>certbot.timer<\/code> for automatic renewal: <code>sudo systemctl status certbot.timer<\/code><\/li>\n\n\n\n<li>If renewal fails, you can renew manually: <code>sudo certbot renew<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Let me know if you need help troubleshooting or further details for any of these steps!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a detailed step-by-step guide based on the instructions you&#8217;ve provided: Step 1: Install Helm Run the following command [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[141,143],"tags":[],"class_list":["post-1478","post","type-post","status-publish","format-standard","hentry","category-devops","category-k8s"],"_links":{"self":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1478"}],"version-history":[{"count":1,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1478\/revisions"}],"predecessor-version":[{"id":1479,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1478\/revisions\/1479"}],"wp:attachment":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}