-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to configure my own CA for k3s ? #1868
Comments
Can you discus your use case a bit? Other than it being fun to experiment with, I'm not sure what the point would be. As far as I know, even the commercial cloud providers just use unique self-signed CAs for each cluster. k3s actually follows best practices and uses three separate CAs. There aren't any specific arguments or options to load existing CA certs, but you can pre-create the files and put them in the correct location and k3s will use them instead of creating new ones. Here's an example: mkdir -p /var/lib/rancher/k3s/server/tls
cd /var/lib/rancher/k3s/server/tls
openssl genrsa -out client-ca.key 2048
openssl genrsa -out server-ca.key 2048
openssl genrsa -out request-header-ca.key 2048
openssl req -x509 -new -nodes -key client-ca.key -sha256 -days 3560 -out client-ca.crt -addext keyUsage=critical,digitalSignature,keyEncipherment,keyCertSign -subj '/CN=k3s-client-ca'
openssl req -x509 -new -nodes -key server-ca.key -sha256 -days 3560 -out server-ca.crt -addext keyUsage=critical,digitalSignature,keyEncipherment,keyCertSign -subj '/CN=k3s-server-ca'
openssl req -x509 -new -nodes -key request-header-ca.key -sha256 -days 3560 -out request-header-ca.crt -addext keyUsage=critical,digitalSignature,keyEncipherment,keyCertSign -subj '/CN=k3s-request-header-ca' After doing this you can install k3s as usual using install.sh and it should use the openssl-generated certs and keys. |
@brandond
I see all new certs are signed by new ca but dynamic-cert.json is having old certificate. Is it bug or I am missing something ? |
The k3s-serving cert isn't handled the same as others. It doesn't get rotated when it expires, either - there's an open issue about it. I'm not sure what the best way is to get it updated on an existing cluster. Maybe try deleting it and the linked secret? |
@brandond
|
Hi, parekhha, I do like you,but get error. kubectl -n kube-system delete secret k3s-serving && sleep 2 #default openssl.cnf: /etc/pki/tls/openssl.cnf echo "restart k3s ..." echo "over" |
It sounds like you have some pods still running with old certificates. If you're going to try to use custom CA certs, you're best off doing it before starting k3s for the first time. |
Yeah, I create my production cluster by k3s install.sh. Instead of restarting our cluster once a year, we want to generate a long time certificates(e.g., a 5-year serving-kube-apiserver.crt). Is there any tool to generate new certs and apply them to my cluster? thanks. |
There is not currently any automated way to do this. Most folks would tell you that you should probably be rebooting to apply kernel and package updates at least once a year. For k3s at least, restarting the service does not affect running pods, so you could just schedule a weekly restart of k3s and not worry about it. |
ok, thank you! |
Possibly related |
Hi, I use vntbbb 's script above to delete all certs after deleting secret and restart k3s, then recreate three CA certs and start k3s but old CA certs coverd my own CA certs. Is there any update has changed certs creation logic? |
Re-opening for validation |
Validated on commit id 2156015 from master branch
|
Just to save other people's time posting here full script that will generate both server side (3 CAs for k8s) and client side (kubectl, argocd, etc) certificates:
|
@dene14 there is actually a page for this in the docs, along with a script to do it for you. https://docs.k3s.io/cli/certificate#using-custom-ca-certificates |
Hi,
I am trying to configure my own ca with k3s. My expectation is, I give my cacert and cakey to k3s and k3s automatically generate all required cert from that and also rotate those certificate if expired.
Is it possible ?
The text was updated successfully, but these errors were encountered: