{"id":144,"date":"2022-06-10T15:58:43","date_gmt":"2022-06-10T12:58:43","guid":{"rendered":"https:\/\/www.gmerden.com\/?p=140"},"modified":"2026-01-31T21:16:00","modified_gmt":"2026-01-31T21:16:00","slug":"tls-certificate-in-k8s","status":"publish","type":"post","link":"https:\/\/www.gmerden.com\/index.php\/2022\/06\/10\/tls-certificate-in-k8s\/","title":{"rendered":"TLS Certificate in K8s"},"content":{"rendered":"\n<p>     I tried to move new server at work. I wanted to install k8s but this time i used microk8s. Microk8s, lightweight k8s deployment tool. It can be easy to manage after read a few documents about it.<\/p>\n\n\n\n<p>I am using Ubuntu on server via following command script<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo snap install microk8s --classic<\/code><\/pre>\n\n\n\n<p>Source : https:\/\/ubuntu.com\/tutorials\/install-a-local-kubernetes-with-microk8s#2-deploying-microk8s<\/p>\n\n\n\n<p>Afterwards i created yaml files and applied to k8s  and i enabled ingress to serve apis which i installed. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: networking.k8s.io\/v1\nkind: Ingress\nmetadata:\n  name: ingress-service\n  annotations:\n    kubernetes.io\/ingress.class: nginx\n    nginx.ingress.kubernetes.io\/use-regex: 'true'\n    nginx.ingress.kubernetes.io\/rewrite-target: \/$1\n    nginx.ingress.kubernetes.io\/enable-access-log: \"false\"\n    nginx.ingress.kubernetes.io\/configuration-snippet: |-\n      proxy_ssl_server_name on;\n      proxy_ssl_name $host;\nspec:\n  tls:\n  - hosts:\n      - your-domain-name.com\n    secretName: tls-secret-2\n#testsecret-tls\n  rules:\n    - host: your-domain-name.com\n      http:\n        paths:\n          - path: \/?(.*)\n            pathType: Prefix\n            # UPDATE THIS LINE ABOVE\n            backend:\n              service:\n                name: appointment-cluster-ip-service\n                port:\n                  number: 8080\ningressClassName: public<\/code><\/pre>\n\n\n\n<p>Also i want to enable tls for secure connection. After a few researches , i understand that i have to create new crt and private key.<\/p>\n\n\n\n<p>System admin has sent pfx file to enable tls. I apllied following command to create key file from pfx.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl pkcs12 -in pfx-filename.pfx -nocerts -out key-filename.key<\/code><\/pre>\n\n\n\n<p>Second step creating decrypted file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl rsa -in key-filename.key -out key-filename-decrypted.key<\/code><\/pre>\n\n\n\n<p>Third step , creating crt file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl pkcs12 -in pfx-filename.pfx -clcerts -nokeys -out crt-filename.crt<\/code><\/pre>\n\n\n\n<p>Fourth step, creating secret on k8s<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl create secret tls tls-secret-2 --cert crt-filename.crt --key key-filename-decrypted.key<\/code><\/pre>\n\n\n\n<p>Consequently, i applied yaml file via following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s kubectl apply -f your-ingress.yml<\/code><\/pre>\n\n\n\n<p>And test if it is done via following command. But i want to mention about this point. After i applied all steps i tried if it was accepting https requests. But it did not. So i went to take a cup of tea and came back about five or ten minutes later. I tested again and it was done \ud83d\ude42<\/p>\n\n\n\n<p>An edit, i realized that i have to concatenate intermediate cert to created primary crt file via following command. Because of following error, Javax.Net.Ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat your_domain_name.crt DigiCertCA.crt &gt;&gt; bundle.crt<\/code><\/pre>\n\n\n\n<p>Source: Nginx: Create CSR &amp; Install SSL Certificate (OpenSSL), DigiCert, <\/p>\n\n\n\n<p><a href=\"https:\/\/www.digicert.com\/kb\/csr-ssl-installation\/nginx-openssl.htm#ssl_certificate_install\">https:\/\/www.digicert.com\/kb\/csr-ssl-installation\/nginx-openssl.htm#ssl_certificate_install<\/a><\/p>\n\n\n\n<p>Have a good day<\/p>\n\n\n\n<p>Source : Configuring a TLS certificate in Kubernetes, A.Dev (2021) , https:\/\/adolfi.dev\/blog\/tls-kubernetes\/, A.D. : 10\/06\/2022<\/p>\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>I tried to move new server at work. I wanted to install k8s but this time i used microk8s. Microk8s, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","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":"","ast-disable-related-posts":"","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-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[3],"tags":[],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-software-development"],"_links":{"self":[{"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":6,"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":452,"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions\/452"}],"wp:attachment":[{"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gmerden.com\/index.php\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}